BitcoinJ generate address from private key

0 votes

I'm facing an issue regarding generating address from private key.

I got the master private key from electrum and from bitcoin core that starts from

xprv9s21xxxxxxxxxxxxxxxxxxxxxxxxxxxx

in bitcoinJ:

ECKey key=ECKey.fromPrivate(prv); // it accepts bytes[] or BigInteger

how can i convert 9s21xxxxxxxxxxxxxxxxx into bytes[] or BigInteger.

Try:

String prvkey=9s21xxxxxxxxxxxxxxxxxxxxx
BigInteger bytes=new BigInteger(priv,16);

it throws exception as it can't convert due to number format.

Try 2:

byte[] bytes=prvkey.getBytes(StandardCharsets.UTF_16);

it generates valid address from ECKey and i send transaction to that address via electrum. but wallet didn't receive money. 

What should i do to convert master private key into BigInteger or bytes[]

Sep 4, 2018 in Blockchain by digger
• 26,740 points
2,293 views

1 answer to this question.

0 votes

Convert string private key into bytes[]:

ECKey key = ECKey.fromPrivate(prv.getBytes());

Or, convert string private key into BigInteger:

BigInteger privKey = Base58.decodeToBigInteger(prv);
ECKey key = ECKey.fromPrivate(privKey);
answered Sep 4, 2018 by slayer
• 29,370 points

Related Questions In Blockchain

0 votes
1 answer

Not able to generate WIF from extended private key

I found the answer to this in the ...READ MORE

answered Aug 29, 2018 in Blockchain by digger
• 26,740 points
1,270 views
+1 vote
0 answers

How to generate bitcoin address from XPUB

How to generate bitcoin addresses from XPUB ...READ MORE

Mar 9, 2022 in Blockchain by Soham
• 9,710 points
1,660 views
0 votes
1 answer

How to get Bitcoin Private Key from an ExtPrivKey using NBitcoin

From what I see in the code ...READ MORE

answered Apr 7, 2022 in Blockchain by Aditya
• 7,680 points
1,268 views
0 votes
1 answer

Generate Ethereum addresses in HD Wallet using public key only (bitcoinj/web3j)

Like Bitcoin, Ethereum uses secp256k1. Ethereum addresses ...READ MORE

answered Apr 12, 2022 in Blockchain by Soham
• 9,710 points
3,771 views
0 votes
1 answer

Bitcoinj send payment from a wallet

The problem actually was with the input ...READ MORE

answered Sep 6, 2018 in Blockchain by slayer
• 29,370 points
1,987 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,942 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,740 points
45,295 views
0 votes
1 answer

How do I add multiple recipients for transactions via Blockchain API?

Convert the recipes into JSON objects. x = ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
924 views
0 votes
1 answer

Bitcoin private key: translate from bash to perl

use bignum; # Get arbitrary precision arithmetic # ...READ MORE

answered Sep 4, 2018 in Blockchain by slayer
• 29,370 points
1,307 views
+1 vote
1 answer

How to generate Bitcoin address?

Convert the hex string back to bytes ...READ MORE

answered Aug 20, 2018 in Blockchain by slayer
• 29,370 points
1,178 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP