簡體   English   中英

web3.js調用傳遞函數返回Solidity函數的無效參數數目

[英]web3.js calling transfer function return Invalid number of arguments to Solidity function

我目前正在使用web3.js在表單提交上使用函數,即transfer(address _to, uint256 _value)

我可以調用合同功能,但會收到錯誤消息:嘗試使用傳遞函數的Solidity函數的參數數目無效,同時提供了令牌的地址和數量。

這是我的部分代碼:

function sendtoken(to, amount){

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

    return settx;
}

調用它(不用擔心,我的合同正確地調用了合同變量

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);
}

任何想法為什么我會收到此錯誤? 我似乎正在提供正確的元素。 我一點都不習慣使用web3.js,我想我可以像調用當前合同中返回正確數據的其他功能一樣調用此函數,以作為令牌和費率的平衡。

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);

魔術,現在正在返回數據

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM