-
-
Save ndelvalle/f30c9b695cffc1794d176173ddc19398 to your computer and use it in GitHub Desktop.
Create bitcoin transaction from BIP38 private key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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