【发布时间】: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