0

I am able to generate the contract just fine, and able to create a wallet, but when I try to deploy the contract on testrpc, I always get an exception saying I dont have enough funds. How can you initialize a wallet using web3j that has initial funds in it?

I create the wallet using WalletUtils, and then use the following code to initialize that account I created with ether while launching testrpc

byte[] keys = Keys.serialize(wallet.getCredentials().getEcKeyPair());
String result = new String(Hex.encodeHex(keys));
String privateKey = result.substring(33, 65);

Then I try to deploy a contract using that wallet I created.

Sorry, edit to the original question, I cannot launch testrpc because I getting 'private key length is invalid'

My real question should be, how do I create a wallet using web3j, get the private key from it, and use that to initialize testrpc with that private key having funds?

  • ganache-cli (formerly testrpc) by default gives each test account 100 ether to start with. So I don't know why you wouldn't have enough funds. Perhaps you can share the code you're running to deploy the contract and tell us more about the account you're using to do it. – user19510 Jan 13 '18 at 1:24
  • So there is something I dont understand here is my process: 1. Create a wallet using WalletUtils.generateFullNewWalletFile(PASSWORD,new File(keyStorePath)); 2. Launch testrpc from java 3. deploy the contract – yemista Jan 13 '18 at 1:26
  • You'll need to use one of the accounts testrpc creates for you. Those have ether preloaded in them. Don't create your own account. – user19510 Jan 13 '18 at 1:30
  • I see. But how can I get them out from testrpc and then have them accessible through web3j? – yemista Jan 13 '18 at 1:31
  • testrpc has an option --account=<private key>,<amount of wei>. I don't know how you're launching it, but perhaps you can pass that option. – user19510 Jan 13 '18 at 1:32

Your Answer

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

Browse other questions tagged or ask your own question.