Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It only takes a minute to sign up.
Sign up to join this communityAnybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top
I´d like to construct an ECKey from a hardcoded private key but it´s not working...
If I run the code in this example the key import is working just fine. But since I actually want so send money I need to import my own key...
I tried this private key L48r9sYN2dtsWHWwJ1Xez27W7a3X7RvG6obrmVgU2JLTFQeUCnkh and used this site to generate it. When I try to make the private key an ECKey like this:
ECKey key = ECKey.fromPrivate(Base58.decodeToBigInteger("L48r9sYN2dtsWHWwJ1Xez27W7a3X7RvG6obrmVgU2JLTFQeUCnkh"));
I´m getting the exception
Exception in thread "main" java.lang.IllegalArgumentException: private key exceeds 32 bytes: 304 bits
I tried the solution form this question with this code
String priv = "L48r9sYN2dtsWHWwJ1Xez27W7a3X7RvG6obrmVgU2JLTFQeUCnkh"; ECKey key1 = DumpedPrivateKey.fromBase58(TestNet3Params.get(), priv).getKey();
Which leads me to this exception
Exception in thread "main" org.bitcoinj.core.AddressFormatException$WrongNetwork: Version code of address did not match acceptable versions for network: 128 at org.bitcoinj.core.DumpedPrivateKey.fromBase58(DumpedPrivateKey.java:59) at com.javamaster.TicTacToeApplication.main(TicTacToeApplication.java:42)
I tried another solution form this question
byte[] b = priv.getBytes(); System.out.println(priv); ECKey key3 = ECKey.fromPrivate(b, true);
It results in the same exception as from the second try.
What is wrong with the key? Should I use another way to generate the private key?
The valid private key is L48r9sYN2dtsWHWwJ1Xez27W7a3X7RvG6obrmVgU2JLTFQeUCn
not L48r9sYN2dtsWHWwJ1Xez27W7a3X7RvG6obrmVgU2JLTFQeUCnkh
. You mistyped and added "kh"
You can get bonuses upto $100 FREE BONUS when you:
💰 Install these recommended apps:
💲 SocialGood - 100% Crypto Back on Everyday Shopping
💲 xPortal - The DeFi For The Next Billion
💲 CryptoTab Browser - Lightweight, fast, and ready to mine!
💰 Register on these recommended exchanges:
🟡 Binance🟡 Bitfinex🟡 Bitmart🟡 Bittrex🟡 Bitget
🟡 CoinEx🟡 Crypto.com🟡 Gate.io🟡 Huobi🟡 Kucoin.
Comments