I use Java and bitcoinj. I have a private key

String str="5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf";

I try to get compress and decompress 2 adresses in this format:

1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm  1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH

I do the first step, try get ECKey:

NetworkParameters params = MainNetParams.get();
      ECKey key;

      if (str.length() == 51 || str.length() == 52) {
          DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, str);
          key = dumpedPrivateKey.getKey();            //ERROR
      } else {
          BigInteger privKey = Base58.decodeToBigInteger(str);
          key = ECKey.fromPrivate(privKey);

and I get an exception:

Exception in thread "main" java.lang.IllegalArgumentException
   at com.google.common.base.Preconditions.checkArgument(Preconditions.java:128)
   at org.bitcoinj.core.ECKey.<init>(ECKey.java:195)
   at org.bitcoinj.core.ECKey.fromPrivate(ECKey.java:243)
   at org.bitcoinj.core.ECKey.fromPrivate(ECKey.java:259)
   at org.bitcoinj.core.DumpedPrivateKey.getKey(DumpedPrivateKey.java:101)
   at com.example.demo2.controllers.AdressFromKey.main(AdressFromKey.java:35)

What am I doing wrong?

1 Answer 1


In bitcoinj, there is a check that indicates an error if the private key is 0 or 1. The above private key is 1, so it is an error.


  • Thanks a lot. My task turned out to be very successful Undecided I am trying to generate these keys keys.lol/bitcoin/… and get the corresponding addresses. They all knock out a bug. Maybe there is some way to hardcode and get these addresses without libraries? Nov 29, 2021 at 7:04
  • It's not impossible if you implement what the library does on your own, but it's easy to use. Nov 30, 2021 at 13:27

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.