Skip to content

Instantly share code, notes, and snippets.

Created June 12, 2019 11:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import org.bitcoins.core.{crypto, protocol, config}
// if you want to get addresses for mainnet, just import
// config.MainNet here instead
import config.TestNet3
import crypto.ECPrivateKey
// this gets all addresses into scope
import protocol._
// this gets all scriptPubKeys into scope
import protocol.script._
// this generates a random private key
val privkey = ECPrivateKey()
// privkey: ECPrivateKey = ECPrivateKey(d82a17b83259d8cacccbaf6fbe07d811a466d13cc5f5d6bcea254a41621496cc,true)
val pubkey = privkey.publicKey
// pubkey: crypto.ECPublicKey = ECPublicKey(0252aa9734dcfb9e8ae8d130790e7f9af5fd47ea76257261aff076216392e06778)
val segwitAddress = {
// see
// for reading resources on the details of scriptPubKeys
// pay-to-witness-pubkey-hash scriptPubKey V0
val scriptPubKey = P2WPKHWitnessSPKV0(pubkey)
Bech32Address(scriptPubKey, TestNet3)
// segwitAddress: Bech32Address = Bech32Address(tb1qzmj0ts9606p9t0pnl3j7nq62svz6m8h42sun9d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment