Advertisement
mmo2112

BitcoinJ create address

Sep 11th, 2019
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. NetworkParameters network = TestNet3Params.get();
  2. String wifPk = "cUNCS8F8n2dgineo4ENshEo4qFDMTLYa7MC31DKSo8whVZaV6FDu";
  3. DumpedPrivateKey wif = DumpedPrivateKey.fromBase58(network, wifPk);
  4. ECKey _ecKey = wif.getKey();
  5.  
  6. Address retrieveAddress = LegacyAddress.fromPubKeyHash(network, _ecKey.getPubKeyHash());
  7. Address addressFromKeyP2KH = Address.fromKey(network, _ecKey, Script.ScriptType.P2PKH);
  8. Address addressFromKeyP2WPKH = Address.fromKey(network, _ecKey, Script.ScriptType.P2WPKH);
  9.  
  10. System.out.println("retrieveAddress: " + retrieveAddress);
  11. System.out.println("addressFromKeyP2KH: " + addressFromKeyP2KH);
  12. System.out.println("addressFromKeyP2WPKH: " + addressFromKeyP2WPKH);
  13.  
  14. List<ECKey> listEcKey = new ArrayList<ECKey>();
  15. listEcKey.add(_ecKey);
  16.  
  17. Script p2shScript = ScriptBuilder.createP2SHOutputScript(1, listEcKey);
  18. Script p2wpkhScript = ScriptBuilder.createP2WPKHOutputScript(_ecKey);
  19. Script p2pk = ScriptBuilder.createP2PKOutputScript(_ecKey);
  20.  
  21. Address p2shAddress = LegacyAddress.fromScriptHash(network, ScriptPattern.extractHashFromP2SH(p2shScript));
  22. Address p2pkAddress = LegacyAddress.fromKey(network, ECKey.fromPublicOnly(ScriptPattern.extractKeyFromP2PK(p2pk)));
  23. Address p2wpkhAddress = LegacyAddress.fromScriptHash(network, ScriptPattern.extractHashFromP2WH(p2wpkhScript));
  24.  
  25. System.out.println("p2shAddress: " + p2shAddress);
  26. System.out.println("p2pkAddress: " + p2pkAddress);
  27. System.out.println("p2wpkhAddress: " + p2wpkhAddress);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement