[Ethereum] Custom balance accounts testrpc

contract-debuggingtestrpctruffle

I am setting up unit tests with for my contracts using truffle. I am using also testrpc, but having accounts with 2.123...... *10^37 Wei is not very helpful to visualise and debug things.

I am trying to setup custom testRPC account balances using $ testrpc --account="<privatekey>,balance" as seen here. However, what I get back is one account with again "infinite ether".

I have also tried to do :

var TestRPC = require("ethereumjs-testrpc");
var accountConfig = [
  {balance: 20000000},
  {balance: 20000000}
];
web3.setProvider(TestRPC.provider({accounts: accountConfig}));

as seen here and here , however truffle complains it cannot find the module "ethereumjs-testrpc".

In short the question then is : how to set up custom account balances for testRPC?

Best Answer

From the documentation, you can explicity specify a new account address and balance using the following syntax:

--account: Specify --account=... (no 's') any number of times passing arbitrary private keys and their associated balances to generate initial addresses:

$ testrpc --account="<privatekey>,balance" [--account="<privatekey>,balance"]

Note that private keys are 64 characters long, and must be input as a 0x-prefixed hex string. Balance can either be input as an integer or 0x-prefixed hex value specifying the amount of wei in that account.

I'd suggest running testrpc without the --account option to get the randomly generated list of addresses, making a note of them, and then using them in conjunction with whatever balances you want them to have (by passing them to --account).