{"id":3101,"date":"2022-08-13T11:42:35","date_gmt":"2022-08-13T02:42:35","guid":{"rendered":"https:\/\/blog.wsd.sh\/?p=3101"},"modified":"2022-08-15T22:03:32","modified_gmt":"2022-08-15T13:03:32","slug":"3101","status":"publish","type":"post","link":"https:\/\/blog.wsd.sh\/?p=3101","title":{"rendered":"<small>bitcoin-core:nodejs\u3067\u306e\u9001\u4fe1<\/small>"},"content":{"rendered":"<p>1. WalletAddress\u306e\u78ba\u8a8d<\/p>\n<pre>\r\n- Alice WalletAddress\r\nbcrt1qqtm00jv39e09uxgtrzwgvk2wyv0umq0tasnr8m\r\n\r\n- bob  WalletAddress\r\nbcrt1qj8mle4z5vw4pkx3mvjn9kkvqmrap55yd6gj4hk\r\n\r\n- calol WalletAddress\r\nbcrt1qhya07e4kejp7phxlnk7rckm5v9skh4jdzuesks\r\n\r\n- Dave WalletAddress\r\nbcrt1q8mnq3xzxh25snzdak4zec8khcy5r7kye3tl4kv\r\n\r\n- eve WalletAddress\r\nbcrt1qhnt96hwgaknldamh4dq3sm5ehqr7nq4capdfg5\r\n\r\n- akira WalletAddress\r\nbcrt1q8gleyvlr4q6kf6rurdx34v7mx363nwqx5c0y0p\r\n<\/pre>\n<p>2. getBalanceByAlice.js<\/p>\n<pre>\r\n$\u3000pwd\r\n\/home\/user02\/bitcoin-core\/test\r\n$ cat getBalanceByAlice.js\r\nconst Client = require('..\/src\/index');\r\nconst config = require('.\/config');\r\n\r\nconst client = new Client(config.AliceWallet);\r\n\r\nasync function _balance() {\r\n        const balance = await client.getBalance();\r\n\r\n        console.log(balance);\r\n}\r\n\r\n_balance();\r\n\r\n$ node  getBalanceByAlice.js\r\n1.226064\r\n<\/pre>\n<p>3. transferFromAliceToEve_1.js<br \/>\n&#8211; <\/p>\n<pre>\r\n$ cat transferFromAliceToEve_1.js\r\nconst Client = require('..\/src\/index');\r\nconst config = require('.\/config');\r\n\r\nconst alice = new Client(config.AliceWallet);\r\n\r\nconst eve_address = \"bcrt1qhnt96hwgaknldamh4dq3sm5ehqr7nq4capdfg5\"\r\n\r\nconst amount = 0.01\r\n\r\nasync function _transfer(from, to_address, amount) {\r\n\r\n        let from_balance, to_balance;\r\n\r\n        from_balance = await from.getBalance();\r\n\r\n        console.log(\"before:from balance:\"+from_balance);\r\n\r\n        const send_result = await from.sendToAddress(to_address, amount);\r\n\r\n        console.log(send_result);\r\n\r\n        const generate_result = await from.generateToAddress(1, to_address);\r\n\r\n        console.log(generate_result);\r\n\r\n        alice_balance = await from.getBalance();\r\n\r\n        console.log(\"after:from balance:\"+alice_balance);\r\n}\r\n\r\n_transfer(alice, eve_address, amount);\r\n\r\n$ node transferFromAliceToEve_1.js\r\nbefore:from balance:1.226064\r\n64875b41df96c08aa083f1f21f8b607e8bbbc2632f1eada71a05a6a7c1148953\r\n[ '765b0d3f5235b2d00d97068cbf25e89b6f98bcbb4535448896376c7b1552415b' ]\r\nafter:from balance:1.215782\r\n<\/pre>\n<p>4. transferFromAliceToBob.js<\/p>\n<pre>\r\n$cat transferFromAliceToBob.js\r\n$ node transferFromAliceToBob.js\r\nconst Client = require('..\/src\/index');\r\nconst config = require('.\/config');\r\nconst client = new Client(config.AliceWallet);\r\nconst address = \"bcrt1qj8mle4z5vw4pkx3mvjn9kkvqmrap55yd6gj4hk\"\r\nconst amount = 0.1\r\n\r\nasync function _transfer(from, to_address, amount) {\r\n\r\n        const comment =  \"drink 1\"\r\n        const comment_to =  \"room 1\"\r\n\r\n        console.log(\"Transfer from alice to bob\")\r\n        let from_balance, to_balance;\r\n        from_balance = await from.getBalance();\r\n        console.log(\"before:from balance:\"+from_balance);\r\n\r\n        const send_result = await from.sendToAddress(to_address, amount, comment, comment_to);\r\n        console.log(send_result);\r\n\r\n        const generate_result = await from.generateToAddress(1, to_address);\r\n        console.log(generate_result);\r\n\r\n        alice_balance = await from.getBalance();\r\n        console.log(\"after:from balance:\"+alice_balance);\r\n        \r\n        const transaction_result = await from.getTransaction(send_result);\r\n        console.log(transaction_result);\r\n}\r\n\r\n_transfer(client, address, amount);\r\n\r\n$ node transferFromAliceToBob.js\r\nTransfer from alice to bob\r\nbefore:from balance:0.963808\r\nca4659a24421d6f48d2a6da59958ce0644d2af71b64b3a5b1ab41581b97a1577\r\n[ '3c64c340a1e6b7d218566e77a81b15490d56936bdf3dca74f02c07aca32617bf' ]\r\nafter:from balance:0.863526\r\n[Object: null prototype] {\r\n  amount: -0.1,\r\n  fee: -0.000282,\r\n  confirmations: 1,\r\n  blockhash: '3c64c340a1e6b7d218566e77a81b15490d56936bdf3dca74f02c07aca32617bf',\r\n  blockheight: 7268,\r\n  blockindex: 1,\r\n  blocktime: 1660373139,\r\n  txid: 'ca4659a24421d6f48d2a6da59958ce0644d2af71b64b3a5b1ab41581b97a1577',\r\n  walletconflicts: [],\r\n  time: 1660373139,\r\n  timereceived: 1660373139,\r\n  'bip125-replaceable': 'no',\r\n  comment: 'drink 1',\r\n  to: 'room 1',\r\n  details: [\r\n    [Object: null prototype] {\r\n      address: 'bcrt1qj8mle4z5vw4pkx3mvjn9kkvqmrap55yd6gj4hk',\r\n      category: 'send',\r\n      amount: -0.1,\r\n      vout: 1,\r\n      fee: -0.000282,\r\n      abandoned: false\r\n    }\r\n  ],\r\n  hex: \u7701\u7565\r\n}\r\n<\/pre>\n<p>5. listtransactionsOfAlice.js<\/p>\n<pre>\r\n$ cat listtransactionsOfAlice.js\r\nconst Client = require('..\/src\/index');\r\nconst config = require('.\/config');\r\nconst client = new Client(config.AliceWallet);\r\nconst count = 20;\r\n\r\nasync function _listtransactions(client, count) {\r\n\r\n        console.log(\"listtransactions  alice\")\r\n\r\n        const list = await client.listTransactions(\"*\", count);\r\n\r\n        console.log(list);\r\n}\r\n\r\n_listtransactions(client, count);\r\n\r\n$ node listtransactionsOfAlice.js\r\n[\r\n  [Object: null prototype] {\r\n    address: 'bcrt1qqtm00jv39e09uxgtrzwgvk2wyv0umq0tasnr8m',\r\n    category: 'immature',\r\n    amount: 0,\r\n    label: '',\r\n    vout: 0,\r\n    confirmations: 24,\r\n    generated: true,\r\n    blockhash: '5e2a67161bf6ed1a0792e30eebb9837a6b111dfbae88e2296c2ebda60a97a618',\r\n    blockheight: 7249,\r\n    blockindex: 0,\r\n    blocktime: 1660361951,\r\n    txid: '5b984611886ce913dcc68aea72bd11633cae32bc7de734f86e6feba1706ba3fd',\r\n    walletconflicts: [],\r\n    time: 1660361951,\r\n    timereceived: 1660361951,\r\n    'bip125-replaceable': 'no'\r\n  },\r\n\u7701\u7565\r\n]\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1. WalletAddress\u306e\u78ba\u8a8d &#8211; Alice WalletAddress bcrt1qqtm00jv39e09uxgtrzwgvk2wyv0umq0tasnr8m &#8211; bob WalletAddress bcr&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/posts\/3101"}],"collection":[{"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3101"}],"version-history":[{"count":12,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/posts\/3101\/revisions"}],"predecessor-version":[{"id":3108,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/posts\/3101\/revisions\/3108"}],"wp:attachment":[{"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}