【问题标题】:web3.js calling transfer function return Invalid number of arguments to Solidity functionweb3.js 调用传递函数返回 Solidity 函数的参数数量无效
【发布时间】:2018-02-20 07:01:15
【问题描述】:

我目前正在使用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 中正确调用了

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,我想我可以调用这个函数,就像我在当前合约上调用其他函数一样,返回正确的数据,作为令牌和费率的平衡。

【问题讨论】:

    标签: javascript jquery ethereum web3js


    【解决方案1】:
    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);
    

    魔术,现在返回数据

    【讨论】:

    猜你喜欢
    • 2019-08-15
    • 2018-11-07
    • 2018-09-16
    • 2020-10-25
    • 2019-03-28
    • 1970-01-01
    • 2020-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多