Skip to content

Instantly share code, notes, and snippets.

@gabmontes
Created December 7, 2017 01:36
Show Gist options
  • Save gabmontes/ab0b5134bde7676f23ef921d1948567e to your computer and use it in GitHub Desktop.
Save gabmontes/ab0b5134bde7676f23ef921d1948567e to your computer and use it in GitHub Desktop.
Create bitcoin transaction from BIP38 private key
const { Transaction } = require('bitcore-lib')
const { decrypt } = require('bip38')
const encryptedKey = '<private key beginning with 6>'
const password = '<private key password>'
const privateKey = decrypt(encryptedKey, password).privateKey
// Check UTXO info at https://insight.bitpay.com/api/addr/<origin address>/utxo
const utxo = {
'txid': '<txid>',
'vout': <vout>,
'scriptPubKey': '<scriptPubKey>',
'satoshis': <satoshis>,
}
const tx = new Transaction()
tx.from(utxo)
tx.to('<to address>', <amount in satoshis>)
tx.fee(30000) // for ~258 bytes
tx.change('<back to origin address?>')
tx.sign(privateKey)
console.log(tx.toString())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment