I am working with the basic truffle
framework. The MetaCoin.sol
file which is installed automatically has the following
contract MetaCoin {
mapping (address => uint) balances;
function MetaCoin() {
balances[tx.origin] = 10000;
}...
What this accomplishes is adding 10000 MetaCoin into account 0. What I want to do is access account 1, 2, 3, perhaps to add MetaCoin or do something else. But I don't know how to do this. I can do it by explicitly including the address (e.g. balances[0x90afa53bce...]
) but this is bad because truffle addresses are not static between sessions.
I know that truffle tests starts out with all accounts in a list, but I want to access them within the contract first, and then test.
Best Answer
In the truffle console you can access them with web3.eth.getBalance(web3.eth.accounts[0]), just replace the zero.
In a Javascript file you can easily access them as showed in the basic metacoin test:
In principle the contract doesn't know on which network it's deployed, therefore I'm not sure that you can do it from within the solidity contract.