I'm testing the following contract using Truffle framework and deploying on TestRPC network.
contract MetaCoin {
mapping (address => uint) balances;
function MetaCoin() {
balances[tx.origin] = 10000;
}
function sendCoin(address receiver, uint amount) returns(bool sufficient) {
if (balances[msg.sender] < amount) return false;
balances[msg.sender] -= amount;
balances[receiver] += amount;
return true;
}
function getBalanceInEth(address addr) returns(uint){
return ConvertLib.convert(getBalance(addr),2);
}
function getBalance(address addr) returns(uint) {
return balances[addr];
}
}
I load it up in the browser and it seems to work. What I wonder is if it is possible to change the coinbase dynamically.
For example, after I've send some MetaCoins from user1 to user2 then I want to change the coinbase to user2 and reload the app to show me the MetaCoins balance of user2.
How can I achieve that?
getBalance.call()
to achieve the same result. It would be better style to make it constant, though