I suffer a steep learning curve at the beginning. My current goal is to set up a testing environment with TestRpc, Truffle and Web3j (wow).

Web3j worked as expected and generated a Java wrapper for the famous HelloWorld contract. TestRpc also works as expected and shows as in the Image.

https://goo.gl/images/V96znv Image: I took this from the web, but it is the same

The image shows the addresses and the private keys. If you use TestRpc, I assume that you have seen it many times.

So back to my simple question. Where or how do I get the public key for the accounts that show in the TestRpc console?

3 Answers 3


Testrpc gives you the private key to each account. To receive the corresponding public key you simply have to multiply the base point of your curve with the private key. This can be done using for example bouncycastle.

The base point for secp256k1 is G=(gx,gy) with:

gx = 55066263022277343669578718895168534326250603453777594175500187360389116729240 gy = 32670510020758816978083085130507043184471273380659243275938904335757337482424


quite easy in fact:

import org.web3j.crypto.ECKeyPair;   
import org.web3j.utils.Numeric;

final ECKeyPair keyPair = ECKeyPair.create(Numeric.toBigInt("0x"));
BigInteger publicKey = keyPair.getPublicKey();

//later to be use in Web3j you may need
 Credentials credentials = Credentials.create(keyPair);

I did not get an anser. But I found a workaround that may help others.

A code example in the Web3j project may be of help if you have the same question. Check for the package org.web3j.crypto. It appears to use org.bouncycastle to generate a full keyset.

 * Create a keypair using SECP-256k1 curve.
 * <p>Private keypairs are encoded using PKCS8
 * <p>Private keys are encoded using X.509
static KeyPair createSecp256k1KeyPair() throws NoSuchProviderException,
        NoSuchAlgorithmException, InvalidAlgorithmParameterException {

    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("ECDSA", "BC");
    ECGenParameterSpec ecGenParameterSpec = new ECGenParameterSpec("secp256k1");
    keyPairGenerator.initialize(ecGenParameterSpec, new SecureRandom());
    return keyPairGenerator.generateKeyPair();

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.