How to create an external account ( personal.newAccount()) equivalent in the ethereumj ? I know I could use the jsonrpc api to do so ? But I read https://github.com/ethereum/ethereumj/issues/335 , which says it could create an account, but it could not, it just generates the address, but does not include/add it to the keystore. How can I add this to the keystore.

1 Answer 1


Firstly you will need the following Maven pom.xml dependency:

        <!--  <type>zip</type>  -->

And here is the code to create a private key / account pair:

import org.ethereum.crypto.ECKey;
import org.spongycastle.util.encoders.Hex;

public class CreateAccount {

    public static void main(String[] args) {
        ECKey key = new ECKey();

        byte[] addr = key.getAddress();
        byte[] priv = key.getPrivKeyBytes();

        String addrBase16 = Hex.toHexString(addr);
        String privBase16 = Hex.toHexString(priv);

        System.out.println("Address     : " + addrBase16);
        System.out.println("Private Key : " + privBase16);

Running the code twice produces the following output:

Address     : 82d4b1c01afaf7f25bb21fd0b4b4c4a7eb7120ce
Private Key : 133965f412d1362645cbd963619023585abc8765c7372ed238374acb884b2b3a

Address     : 68ccabefc7f4ae21ce0df1d98e50e099d7fc290f
Private Key : 1caeb7f26cb9f3cc7d9d0dbcdd3cf3cb056dbc011ec9013e8f3b8cdb2f193b32

Verifying the information with https://www.myetherwallet.com/#view-wallet-info: enter image description here

enter image description here

And note that the accounts created in EthereumJ are all lowercase while the accounts generated from the private keys using MyEtherWallet are mixed case. This is because MyEtherWallet is using the new checksummed accounts. See Yet another cool checksum address encoding #55.

  • I am not using Wallet. And I am running on a private network. My intention was to let the users access the java code to create their external accounts in the private network. May 24, 2016 at 19:15
  • You don't need MyEtherWallet. I included the images just to confirm that the private key/account pairs are valid. May 24, 2016 at 19:23
  • 2
    If you are asking how the Java generated accounts can be imported into geth, you will have to use the command geth account import private-key-file-to-delete-when-completed where the contents of the file is your generated private key. Once imported into geth, your accounts will be available in eth.accounts. EthereumJ does not interact with your geth keystore through the Java code. You can use the personal.newAccount() API as listed in github.com/ethereum/go-ethereum/wiki/… but you will have to use your own code to access the IPC or RPC API May 24, 2016 at 19:43
  • 2
    @The Neo Noir Developer Just a note: when you create a new account using tools you are unfamiliar with, you want to cross-check using a different client/language the private key -> address derivation to insure everything is good. In this example, you create w/ Java & you verify with Javascript. You could also verify with python or go or rust or any of the other clients/languages available. It's making sure the private key unlocks the address you saved. Otherwise you might send to an address you don't actually have access to.
    – tayvano
    May 25, 2016 at 0:47
  • 1
    And, here is a link to importing a plain private key into geth: ethereum.stackexchange.com/questions/465/…
    – tayvano
    May 25, 2016 at 0:47

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.