简体   繁体   English

web3.js调用传递函数返回Solidity函数的无效参数数目

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

I'm currently using web3.js to use a function on form submit, which is transfer(address _to, uint256 _value) 我目前正在使用web3.js在表单提交上使用函数,即transfer(address _to, uint256 _value)

I'm able to call contract function, but I get Erro: Invalid number of arguments to Solidity function trying to use the transfer function, suppling both to address and amount of token. 我可以调用合同功能,但会收到错误消息:尝试使用传递函数的Solidity函数的参数数目无效,同时提供了令牌的地址和数量。

Here part of my code: 这是我的部分代码:

function sendtoken(to, amount){

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

    return settx;
}

Calling it (don't worry, my contract correctly called in contract 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);

This is where I get the error. 这是我得到错误的地方。 Here the contract function: 这里的合同功能:

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

Any ideas why I get this error? 任何想法为什么我会收到此错误? I seems to be suppling right element. 我似乎正在提供正确的元素。 I'm not used to web3.js at all, and I thought I could call this function same as I fo withs others on current contract that return correct data, as balance of token and rate. 我一点都不习惯使用web3.js,我想我可以像调用当前合同中返回正确数据的其他功能一样调用此函数,以作为令牌和费率的平衡。

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

To : 至 :

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

Magic, now returning data 魔术,现在正在返回数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 web3.js 将数字作为 uint256 传递给 Solidity 函数 - How to pass number as uint256 to Solidity function using web3.js Solidity函数将空数组返回到web3.js - Solidity function returns empty array to web3.js 使用Web3.js将价值从Solidity合同转移到Ganache帐户 - Transfer Value From Solidity Contract To Ganache Account With Web3.js 通过javascript(web3.js)从部署的智能合约中调用特定的solidity函数 - Call specific solidity function from deployed smart contract within react through javascript (web3.js) 无效的参数个数 - Invalid Number of arguments in Solidity 幻影钱包中的“TypeError:x.pubkey.toBase58 不是函数”...使用@solana/web3.js 将 sol 转移到 JavaScript 中的另一个帐户 - "TypeError: x.pubkey.toBase58 is not a function" in phantom wallet...transfer sol to another account in JavaScript with@solana/web3.js Promise.all完成并出现错误错误:Solidity函数(元掩码)的参数数目无效 - Promise.all finished with error Error: Invalid number of arguments to Solidity function (Metamask) 在Azure Function上使用web3.js调用以太坊 - Call Ethereum using web3.js on Azure Function 通过 web3.js 调用和访问智能合约功能? - Call and access smart contract function through web3.js? web3.js调用智能合约函数无响应 - Call smart contract function by web3.js without response
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM