7

I am new to Ethereum. I have some questions concerning the use of ethers(in stead of MetaCoins) with truffle and testrpc.

1. By default, do the accounts of testrpc contain the currency in ethers? If yes, how to know the amount(ex: from truffle console)?
2. I was looking for tutorials about transfering and receiving ethers in testrpc but found nothing. Does anyone have a good tuto?

Thanks in advance!!

6

In testrpc, you can specify an address and it initial balance.

i. create an Ethereum account and get the address and the private key You can for example use MyEtherWallet. After generating an account, you got:

enter image description here

  • Address = 0x198E13017D2333712Bd942d8B028610b95C363da

  • Private Key = 7231a774a538fce22a329729b03087de4cb4a1119494db1c10eae3bb491823e7

ii. Start testrpc and specify the account you want to use and the initial balance (in WEI 1 ether = 1000000000000000000 wei)

According to the testrpc documentation: $ testrpc --account="<privatekey>,balance" [--account="<privatekey>,balance"] so you can run it like that :

$ testrpc --account="0x7231a774a538fce22a329729b03087de4cb4a1119494db1c10eae3bb491823e7, 10000000000000000000"

iii. To check the balance with truffle console

$ truffle console
> web3.fromWei(MetaCoins.web3.eth.getBalance(MetaCoins.web3.eth.coinbase), 'ether')
{ [String: '10'] s: 1, e: 15, c: [ 10 ] }
3

Note that the above (@greg-jeanmart answer) is correct, except the missing 0x in front of the private key. 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.

$ testrpc --account="0x7231a774a538fce22a329729b03087de4cb4a1119494db1c10eae3bb491823e7, 10000000000000000000"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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