I've written a simple token contract for testing purposes:
pragma solidity ^0.4.18;
contract TestToken {
uint public totalSupply;
mapping(address => uint) public balanceOf;
function transfer(address to, uint amount) public returns (bool) {
require(balanceOf[msg.sender] >= amount);
balanceOf[msg.sender] -= amount;
balanceOf[to] += amount;
return true;
}
function credit(address to, uint amount) public {
balanceOf[to] += amount;
totalSupply += amount;
}
function debit(address from, uint amount) public {
balanceOf[from] -= amount;
totalSupply -= amount;
}
}
Whenever I call the credit
method on the contract and pass the address of another contract as parameter, everything works as expected:
token.methods.credit(wallet._address, 500000).send({from: accounts[0], gas: "0xB3E4", gasPrice: "0x4A817C800", value: "0x"})
The status of the transaction is 0x1
.
The balance is updated:
token.methods.balanceOf(wallet._address).call()
'500000'
But when I pass the address of a regular ethereum account as a parameter, the transaction gets mined, but nothing happens.
token.methods.credit(accounts[0], 500000).send({from: accounts[0], gas: "0xB3E4", gasPrice: "0x4A817C800", value: "0x"})
The status of the transaction is 0x0
.
The balance doesn't change:
token.methods.balanceOf(accounts[0]).call()
'0'
Comparing the resulting signed transaction objects, the only difference other than the data
field is that the signature v
value is always 0
when the transaction fails and 1
when the transaction succeeds. But I'm not sure what that means.
Update:
Seems like it's not even contract vs non-contract, it's just that some addresses don't work.
For example, this works:
token.methods.credit('0xd2d0aD819B2679FBDD5C75F93fa13242bfd7E2A5', 500000000000000000).send({from: accounts[0], gas: "0xB3E4", gasPrice: "0x4A817C800", value: "0x"})
This doesn't:
token.methods.credit('0xc4beccd2ebdb32203800dfbc60ff0dd7c2762b48', 500000000000000000).send({from: accounts[0], gas: "0xB3E4", gasPrice: "0x4A817C800", value: "0x"})