[Ethereum] How to get the raw private key from a WalletFile object

androidprivate-keyweb3j

How can I get the raw private key from a WalletFile object?

Here is how I am creating the wallet.

String seed = UUID.randomUUID().toString();
ECKeyPair exKey = Keys.createEcKeyPair();

BigInteger privateKey = exKey.getPrivateKey();
BigInteger publicKey = exKey.getPublicKey();

WalletFile wallet = Wallet.createLight(seed,exKey);

Here is the code where I am sending a transaction,and I need the private key created previously.

Credentials credentials = Credentials.create("MY PRIVATE KEY");

 TransactionReceipt transactionReceipt = Transfer.sendFunds(
                    web3j, credentials, accountTo,
                    BigDecimal.valueOf(0.5),Convert.Unit.ETHER).sendAsync().get();

Best Answer

I found the solution to the problem, of how to get the private key after generate a wallet:

 Credentials credentials = Credentials.create(Wallet.decrypt(seed, wallet));

 String privateKeyGenerated = credentials.getEcKeyPair().getPrivateKey().toString(16);
Related Topic