Skip to content

Instantly share code, notes, and snippets.

@AlwaysBCoding
Created December 3, 2017 22:49
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save AlwaysBCoding/4af36dfc7c6e7d11c0af1621b695a944 to your computer and use it in GitHub Desktop.
Save AlwaysBCoding/4af36dfc7c6e7d11c0af1621b695a944 to your computer and use it in GitHub Desktop.
DecypherTV (Youtube) - Bitcoin Screencast
// Create a new directory, install bitcore-explorers, and run the node shell
mkdir bitcoin && cd bitcoin
npm install --save bitcore-explorers
node
// Require the Bitcore libraries into the global namespace
var bitcore = require(“bitcore-lib”)
var explo = require(“bitcore-explorers”)
var shell = {}
// Generate a new Bitcoin address
var slug = “AlwaysBCoding!BitcoinScreencast1”
var hash = bitcore.crypto.Hash.sha256(new Buffer(slug))
var bn = bitcore.crypto.BN.fromBuffer(hash)
var pKey = bitcore.PrivateKey(bn)
var addr = pKey.toAddress()
// Link to how Bitcoin addresses are created
"https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses#How_to_create_Bitcoin_Address"
// Connect your local shell with a remote BitPay node
var insight = new explo.Insight()
// Get Info about an address
insight.address(addr, (error, result) => { shell.addr = result })
insight.getUnspentUtxos(addr, (error, result) => { shell.utxos = result })
// Create a Bitcoin transaction
var tx = bitcore.Transaction()
tx.from(utxoObject) // As many times as needed
tx.fee(feeAmount) // In Satoshis
tx.to(addr2, amount) // In Satoshis
tx.change(addr) // Send remaining balance back to this account
tx.addData() // Add metadata to the transaction
tx.sign(privateKey)
tx.serialize() // Check for errors
// Send the Bitcoin transaction to the live network
insight.broadcast(tx, (error, txId) => { shell.error = error; shell.txId = txId })
@advoket1189
Copy link

Am getting errors how can I fix them

@StuartGrossman
Copy link

Thank you so much man, this is exactly what I needed.

@12SohailBlockchain
Copy link

sir how i can create fake bitcoin transaction kindly suggest me plz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment