I would like to build an ECKey from a hard-coded private key but it doesn’t work …
If I run the code in this Example key import works fine. But since I really want to send money, I have 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 get the exception
Exception in thread "main" java.lang.IllegalArgumentException: private key exceeds 32 bytes: 304 bits
I tried the solution form that question with this code
String priv = "L48r9sYN2dtsWHWwJ1Xez27W7a3X7RvG6obrmVgU2JLTFQeUCnkh"; ECKey key1 = DumpedPrivateKey.fromBase58(TestNet3Params.get(), priv).getKey();
Which brings 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 form of solution that question
byte b = priv.getBytes(); System.out.println(priv); ECKey key3 = ECKey.fromPrivate(b, true);
This results in the same exception as from the second attempt.
What’s wrong with the key? Should I use some other way to generate the private key?