Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/makevoid/bitcore-lib-tutorial
Bitcoin Private Key Generation and Transaction Creation and Submission tutorial using bitcore-lib
https://github.com/makevoid/bitcore-lib-tutorial
bitcoin bitcoin-sample-code bitcoin-transaction bitcoin-transaction-example bitcore bitcore-lib blockchain blockchain-bitcoin crypto example learn-bitcoin learn-blockchain sample-code study-bitcoin tutorial utxo
Last synced: about 2 months ago
JSON representation
Bitcoin Private Key Generation and Transaction Creation and Submission tutorial using bitcore-lib
- Host: GitHub
- URL: https://github.com/makevoid/bitcore-lib-tutorial
- Owner: makevoid
- Created: 2020-03-16T15:28:20.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-02-13T23:45:40.000Z (almost 3 years ago)
- Last Synced: 2024-04-08T16:25:15.302Z (9 months ago)
- Topics: bitcoin, bitcoin-sample-code, bitcoin-transaction, bitcoin-transaction-example, bitcore, bitcore-lib, blockchain, blockchain-bitcoin, crypto, example, learn-bitcoin, learn-blockchain, sample-code, study-bitcoin, tutorial, utxo
- Language: JavaScript
- Homepage:
- Size: 1.38 MB
- Stars: 7
- Watchers: 3
- Forks: 4
- Open Issues: 6
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
### bitcore-lib-tutorial
This sameple code will let you generate a private key, create a transaction and submit it via with bitcore-lib and Javascript
---
Creating a private key and sending a bitcoin transaction in 30 lines of code
- run `node create-key.js` to create a new private key (saved by the script in `private-key.txt`)
- fund the account with 1 millibit or less
- run `node index.js` (by default it will create and submit a transaction paying 0.1 btc to the same address)The code is the following:
```js
const { readFileSync } = require('fs')
const bitcoin = require('bitcore-lib')
const { PrivateKey, Transaction } = bitcoinconst pvtKeyString = readFileSync('./private-key.txt').toString().trim()
const pvtKey = new PrivateKey(pvtKeyString)const address = pvtKey.toAddress().toString()
console.log("private key:", pvtKey.toString())
console.log("address:", address)const getUTXOs = require('./blockchain-api/get-utxos')
const pushTx = require('./blockchain-api/push-tx')
// const { pushTx, getUTXOs } = require('./blockchain-api') // TODO: NPM MODULE;(async () => {
try {
let utxos = await getUTXOs({ address })utxos = [ utxos[0] ]
console.log("utxos:", utxos)
const amount = 10000 // 10k sats (0.1mbtc)
const tx = new Transaction()
.from(utxos)
.to(address, amount)
.change(address)
.fee(1000)
.sign(pvtKey)const txHex = tx.serialize()
console.log("tx:", txHex)
const { success, txHash } = pushTx(txHex)
console.log("success:", success, "txHash:", txHash)} catch (err) {
console.error(err)
}
})()```
Creating a private key and sending a bitcoin transaction in 30 lines of code - #coding #bitcoin #tx #utxo #bitcoin-tx #bitcoin-utxo
---
notes about js JS bitcoin libraries:
`bitcore-lib.js` (purely didatical version - [this version])
`bitcoinjs-lib.js` (TODO: create a more practical version using bitcoinjs-lib or a wrapper)
---
@makevoid