{"id":18492482,"url":"https://github.com/makevoid/bitcore-lib-tutorial","last_synced_at":"2025-04-08T21:31:17.577Z","repository":{"id":43900731,"uuid":"247746421","full_name":"makevoid/bitcore-lib-tutorial","owner":"makevoid","description":"Bitcoin Private Key Generation and Transaction Creation and Submission tutorial using bitcore-lib","archived":true,"fork":false,"pushed_at":"2022-02-13T23:45:40.000Z","size":1442,"stargazers_count":7,"open_issues_count":6,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T18:37:54.103Z","etag":null,"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"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/makevoid.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-16T15:28:20.000Z","updated_at":"2025-03-18T09:19:30.000Z","dependencies_parsed_at":"2022-09-24T23:02:09.332Z","dependency_job_id":null,"html_url":"https://github.com/makevoid/bitcore-lib-tutorial","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makevoid%2Fbitcore-lib-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makevoid%2Fbitcore-lib-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makevoid%2Fbitcore-lib-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makevoid%2Fbitcore-lib-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/makevoid","download_url":"https://codeload.github.com/makevoid/bitcore-lib-tutorial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247931291,"owners_count":21020208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["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"],"created_at":"2024-11-06T13:08:12.947Z","updated_at":"2025-04-08T21:31:12.568Z","avatar_url":"https://github.com/makevoid.png","language":"JavaScript","readme":"### bitcore-lib-tutorial\n\nThis sameple code will let you generate a private key, create a transaction and submit it via with bitcore-lib and Javascript\n\n---\n\nCreating a private key and sending a bitcoin transaction in 30 lines of code\n\n- run `node create-key.js` to create a new private key (saved by the script in `private-key.txt`)\n- fund the account with 1 millibit or less\n- run `node index.js` (by default it will create and submit a transaction paying 0.1 btc to the same address)\n\nThe code is the following:\n\n```js\nconst { readFileSync } = require('fs')\nconst bitcoin = require('bitcore-lib')\nconst { PrivateKey, Transaction } = bitcoin\n\nconst pvtKeyString = readFileSync('./private-key.txt').toString().trim()\nconst pvtKey = new PrivateKey(pvtKeyString)\n\nconst address = pvtKey.toAddress().toString()\n\nconsole.log(\"private key:\", pvtKey.toString())\nconsole.log(\"address:\", address)\n\nconst getUTXOs  = require('./blockchain-api/get-utxos')\nconst pushTx    = require('./blockchain-api/push-tx')\n// const { pushTx, getUTXOs } = require('./blockchain-api') // TODO: NPM MODULE\n\n;(async () =\u003e {\n  try {\n    let utxos = await getUTXOs({ address })\n\n    utxos = [ utxos[0] ]\n\n    console.log(\"utxos:\", utxos)\n\n    const amount = 10000 // 10k sats (0.1mbtc)\n\n    const tx = new Transaction()\n      .from(utxos)\n      .to(address, amount)\n      .change(address)\n      .fee(1000)\n      .sign(pvtKey)\n\n    const txHex = tx.serialize()\n\n    console.log(\"tx:\", txHex)\n\n    const { success, txHash } = pushTx(txHex)\n    console.log(\"success:\", success, \"txHash:\", txHash)\n\n  } catch (err) {\n    console.error(err)\n  }\n})()\n\n```\n\nCreating a private key and sending a bitcoin transaction in 30 lines of code -  #coding #bitcoin #tx #utxo #bitcoin-tx #bitcoin-utxo\n\n---\n\nnotes about js JS bitcoin libraries:\n\n\n`bitcore-lib.js` (purely didatical version - [this version])\n\n`bitcoinjs-lib.js` (TODO: create a more practical version using bitcoinjs-lib or a wrapper)\n\n\n---\n\n@makevoid\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmakevoid%2Fbitcore-lib-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmakevoid%2Fbitcore-lib-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmakevoid%2Fbitcore-lib-tutorial/lists"}