Skip to content

Instantly share code, notes, and snippets.

@CosimoSguanci
Last active October 25, 2018 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CosimoSguanci/cce9506b2ff875da019c5f5b15876a36 to your computer and use it in GitHub Desktop.
Save CosimoSguanci/cce9506b2ff875da019c5f5b15876a36 to your computer and use it in GitHub Desktop.
Java code to create LTC, DASH etc... addresses using BitcoinJ
import org.bitcoinj.core.*;
int PREFIX = XXX;
/*PREFIX ->
48: LTC
76: DASH
30: DOGE
7352: ZEC
38: BCH
...*/
ECKey key = new ECKey();
DumpedPrivateKey privKey = key.getPrivateKeyEncoded(NetworkParameters.prodNet());
byte[] shato = Sha256Hash.hash(key.getPubKey());
Ripemd160 r = Ripemd160.from(shato);
byte[] ripemdato = r.bytes();
byte[] prefixAdded = new byte[ripemdato.length + 1];
prefixAdded[0] = PREFIX;
int j = 1;
for (int i = 0; i < ripemdato.length; i++) {
prefixAdded[j++] = ripemdato[i];
}
byte[] shato1 = Sha256Hash.hash(prefixAdded);
byte[] shato2 = Sha256Hash.hash(shato1);
byte[] checksum = new byte[4];
for (int i = 0; i < 4; i++) {
checksum[i] = shato2[i];
}
byte[] finalAdd = new byte[prefixAdded.length + 4];
for (int i = 0; i < prefixAdded.length; i++) {
finalAdd[i] = prefixAdded[i];
}
finalAdd[prefixAdded.length] = checksum[0];
finalAdd[prefixAdded.length + 1] = checksum[1];
finalAdd[prefixAdded.length + 2] = checksum[2];
finalAdd[prefixAdded.length + 3] = checksum[3];
String address = Base58.encode(finalAdd);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment