2017-09-11 34 views
0

我目前使用web3.js使用的形式提交功能,这是transfer(address _to, uint256 _value)web3.js调用传递函数返回无效参数数密实度的功能

我能够调用合同函数,但我得到Erro:尝试使用传递函数的Solidity函数的参数数量无效,同时提供地址和令牌量。我的代码

这里部分:

function sendtoken(to, amount){ 


var to = to; 
var amount = amount; 




    var settx = contract.transfer(to,amount); 

return settx; 
    } 

调用它(别担心,我的合同正确调用合同VAR

var formData = getFormObj("tokeform"); 

console.log(formData.destinationtoke); 
console.log(formData.amounttoke); 
var tx = sendtoken(destinationtoke, amounttoke); 
var tx = JSON.stringify(tx, null, " "); 

console.log(tx); 

这是我得到的错误这里的合同。功能:

function transfer(address _to, uint256 _value) 
    { 
     if (genesisAddress[_to]) throw; 

     if (balances[msg.sender] < _value) throw; 

     if (balances[_to] + _value < balances[_to]) throw; 

     if (genesisAddress[msg.sender]) 
     { 
      minedBlocks = block.number - initialBlockCount; 
     if(minedBlocks % 2 != 0){ 
      minedBlocks = minedBlocks - 1; 
     } 
      if (minedBlocks < 23652000) 
      { 
        availableAmount = rewardPerBlockPerAddress*minedBlocks; 
        totalMaxAvailableAmount = initialSupplyPerAddress - availableAmount; 
        availableBalance = balances[msg.sender] - totalMaxAvailableAmount; 
        if (_value > availableBalance) throw; 
      } 
     } 
     balances[msg.sender] -= _value; 
     balances[_to] += _value; 
     Transfer(msg.sender, _to, _value); 
    } 

任何想法,为什么我得到这个错误?我似乎是suppling正确的元素。我不是我以为我可以调用这个函数,就像我在当前合同上的其他人一样,返回正确的数据,作为令牌和速率的平衡。

回答

0
console.log(formData.destinationtoke); 
console.log(formData.amounttoke); 
var tx = sendtoken(destinationtoke, amounttoke); 

要:

console.log(formData.destinationtoke); 
console.log(formData.amounttoke); 
var tx = sendtoken(formData.destinationtoke, formData.amounttoke); 

魔术,现在返回数据

+0

检查:https://stackoverflow.com/questions/46741374/web3-eth-sendtransaction-sending-to-random - 地址 – btc4cash

+0

我成功发送了tx,但它随机地址了-_- – btc4cash