2017-09-11 31 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