Я использую официальный пример кода ERC20 отсюда: https://www.ethereum.org/token
У меня в трюфеле все работает нормально, но когда я вызываю эту функцию:
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
я получилError: Invalid number of arguments to Solidity function
Я запускаю эти команды из консоли трюфеля:
var token;
Token.deployed().then((res) => {token = res});
var alice = '0xbb452da6021229d93b28a6fea487fd3098eb8b16';
token.transfer(alice, 44);
Я скопировал адрес из учетных записей, перечисленных testrpc Есть идеи, что происходит? Спасибо!
Вам не хватает параметра from:account.
var account_one = "0x1234..."; // the address calling this function. Get the list of accounts and use account[0];
token.transfer(alice, 44, {from: account_one}).then(function(tx_id) {
// If this callback is called, the transaction was successfully processed.
// Note that Ether Pudding takes care of watching the network and triggering
// this callback.
alert("Transaction successful!")
}).catch(function(e) {
// There was an error! Handle it.
})
Как раз для тех, кто пытается обойтись без трюфеля (и с метамаской web3 js).
Я вызвал эту функцию ниже при нажатии кнопки для целей тестирования, и она правильно отправила токены.
Примечание. При нажатии на кнопку активируется подтверждение метамаски, отправка которого приведет к переносу токенов после успешного майнинга в блок.
function transferTokens()
{
if (typeof web3 == 'undefined') {console.log("Metamask Not found"); return; }
var contrctAddress = "PLACE_YOUR_CONTRAT_ADDRESS"; //address of token contract
var abi = []; //REPLACE JSON OF your token contract
var MyContract = web3.eth.contract(abi);
var recipient = "RICIPIENT_ADDRESS"; //to whom you want to send the tokens to
var myContractInstance = MyContract.at(contrctAddress);
var tokensToSend = 2; //replace with number of tokens to send
var weiAmount = tokensToSend*1e18;
web3.eth.getAccounts(function(error, result) {
myContractInstance.transfer(recipient ,weiAmount,function (err, result) {
if (err) {
console.log(err); //handle the error
return;
}
else
{
console.log('success'); //your code for success
}
}); });
}
отметка
отметка
pabloruiz55