I'd like to test a contract using ~100s of different accounts. To start with I'd like to encapsulate contract interactions with successive addresses in a for loop. For argument's sake, using this contract:

contract UnitCounter {
    mapping (address => uint256) public UnitsFrom;
    uint256 public TotalUnits;

    function submitUnits(uint256 Units) {
        UnitsFrom[msg.sender] = Units;
        TotalUnits += Units;

They way I imagine doing this is with the following pseudo code (where abi is from above):

var MyContract = web3.eth.contract(abi)
var myContractInstance = MyContract.at('0xE522E4A145f345925c80C5Cf4b67a5fa00304875')
var randnumberlist = [4,5,1,3,8,7,2,8,9,9,2]
for (var x = 0; x < 10; x++){
    eth.sendTransaction({from: eth.coinbase, to: eth.accounts[personal.listAccounts.length-1], gasPrice: "1000"})
    var randnumberlist = [4,5,1,3,8,7,2,8,9,9,2]
    myContractInstance.submitUnits(rand, {from: eth.accounts[personal.listAccounts.length-1], gas:3000000})

Is it possible to achieve loops like the above using the geth javascript console? If not, could I use the geth command line options with a loop implemented on the OS command line?

Looking at the docs it seems this is not possible. How else might I achieve it?


I think I've almost managed (code amended). However I'm now getting this error:

ReferenceError: 'MyContractInstance' is not defined
    at <anonymous>:10:1

Possibly I need to wait for the transaction to be mined first.

  • I'm not sure if your example is taken from actual code, but it looks like it's got a bit of a bug. submitUnits uses = to set UnitsFrom, but TotalUnits is increased with +=. Commented Jan 5, 2017 at 22:58
  • @MatthewSchmidt thanks - that was intentional - a mapping and a running total. Code is actually recycled from this question.
    – Lee
    Commented Jan 6, 2017 at 10:25
  • There was a typo myContractInstance vs MyContractInstance - that's what caused the error...
    – Lee
    Commented Apr 6, 2017 at 9:44

1 Answer 1


It looks like you've got a handle on this anyway, but there's probably an easier way to go about testing with hundreds of accounts: testrpc.

With testrpc -a 1000 you can create a simulated blockchain with a thousand virtual accounts filled with ether. It will be vastly faster to use it as well, since testrpc does not actually mine, and you will not have to spend any time fooling with sending virtual ETH around. To use testrpc with geth's console, use geth attach rpc:http://localhost:8545.

As for the second question, contract.at() returns immediately--there's no mining involved, as it's used for already existing contracts. Are you sure what you're getting out of web3.eth.contract() is actually a contract object?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.