[英]How to pass number as uint256 to Solidity function using web3.js
[英]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.