bitcoin-core:nodejsでの送信

1. WalletAddressの確認

- Alice WalletAddress
bcrt1qqtm00jv39e09uxgtrzwgvk2wyv0umq0tasnr8m

- bob  WalletAddress
bcrt1qj8mle4z5vw4pkx3mvjn9kkvqmrap55yd6gj4hk

- calol WalletAddress
bcrt1qhya07e4kejp7phxlnk7rckm5v9skh4jdzuesks

- Dave WalletAddress
bcrt1q8mnq3xzxh25snzdak4zec8khcy5r7kye3tl4kv

- eve WalletAddress
bcrt1qhnt96hwgaknldamh4dq3sm5ehqr7nq4capdfg5

- akira WalletAddress
bcrt1q8gleyvlr4q6kf6rurdx34v7mx363nwqx5c0y0p

2. getBalanceByAlice.js

$ pwd
/home/user02/bitcoin-core/test
$ cat getBalanceByAlice.js
const Client = require('../src/index');
const config = require('./config');

const client = new Client(config.AliceWallet);

async function _balance() {
        const balance = await client.getBalance();

        console.log(balance);
}

_balance();

$ node  getBalanceByAlice.js
1.226064

3. transferFromAliceToEve_1.js

$ cat transferFromAliceToEve_1.js
const Client = require('../src/index');
const config = require('./config');

const alice = new Client(config.AliceWallet);

const eve_address = "bcrt1qhnt96hwgaknldamh4dq3sm5ehqr7nq4capdfg5"

const amount = 0.01

async function _transfer(from, to_address, amount) {

        let from_balance, to_balance;

        from_balance = await from.getBalance();

        console.log("before:from balance:"+from_balance);

        const send_result = await from.sendToAddress(to_address, amount);

        console.log(send_result);

        const generate_result = await from.generateToAddress(1, to_address);

        console.log(generate_result);

        alice_balance = await from.getBalance();

        console.log("after:from balance:"+alice_balance);
}

_transfer(alice, eve_address, amount);

$ node transferFromAliceToEve_1.js
before:from balance:1.226064
64875b41df96c08aa083f1f21f8b607e8bbbc2632f1eada71a05a6a7c1148953
[ '765b0d3f5235b2d00d97068cbf25e89b6f98bcbb4535448896376c7b1552415b' ]
after:from balance:1.215782

4. transferFromAliceToBob.js

$cat transferFromAliceToBob.js
$ node transferFromAliceToBob.js
const Client = require('../src/index');
const config = require('./config');
const client = new Client(config.AliceWallet);
const address = "bcrt1qj8mle4z5vw4pkx3mvjn9kkvqmrap55yd6gj4hk"
const amount = 0.1

async function _transfer(from, to_address, amount) {

        const comment =  "drink 1"
        const comment_to =  "room 1"

        console.log("Transfer from alice to bob")
        let from_balance, to_balance;
        from_balance = await from.getBalance();
        console.log("before:from balance:"+from_balance);

        const send_result = await from.sendToAddress(to_address, amount, comment, comment_to);
        console.log(send_result);

        const generate_result = await from.generateToAddress(1, to_address);
        console.log(generate_result);

        alice_balance = await from.getBalance();
        console.log("after:from balance:"+alice_balance);
        
        const transaction_result = await from.getTransaction(send_result);
        console.log(transaction_result);
}

_transfer(client, address, amount);

$ node transferFromAliceToBob.js
Transfer from alice to bob
before:from balance:0.963808
ca4659a24421d6f48d2a6da59958ce0644d2af71b64b3a5b1ab41581b97a1577
[ '3c64c340a1e6b7d218566e77a81b15490d56936bdf3dca74f02c07aca32617bf' ]
after:from balance:0.863526
[Object: null prototype] {
  amount: -0.1,
  fee: -0.000282,
  confirmations: 1,
  blockhash: '3c64c340a1e6b7d218566e77a81b15490d56936bdf3dca74f02c07aca32617bf',
  blockheight: 7268,
  blockindex: 1,
  blocktime: 1660373139,
  txid: 'ca4659a24421d6f48d2a6da59958ce0644d2af71b64b3a5b1ab41581b97a1577',
  walletconflicts: [],
  time: 1660373139,
  timereceived: 1660373139,
  'bip125-replaceable': 'no',
  comment: 'drink 1',
  to: 'room 1',
  details: [
    [Object: null prototype] {
      address: 'bcrt1qj8mle4z5vw4pkx3mvjn9kkvqmrap55yd6gj4hk',
      category: 'send',
      amount: -0.1,
      vout: 1,
      fee: -0.000282,
      abandoned: false
    }
  ],
  hex: 省略
}

5. listtransactionsOfAlice.js

$ cat listtransactionsOfAlice.js
const Client = require('../src/index');
const config = require('./config');
const client = new Client(config.AliceWallet);
const count = 20;

async function _listtransactions(client, count) {

        console.log("listtransactions  alice")

        const list = await client.listTransactions("*", count);

        console.log(list);
}

_listtransactions(client, count);

$ node listtransactionsOfAlice.js
[
  [Object: null prototype] {
    address: 'bcrt1qqtm00jv39e09uxgtrzwgvk2wyv0umq0tasnr8m',
    category: 'immature',
    amount: 0,
    label: '',
    vout: 0,
    confirmations: 24,
    generated: true,
    blockhash: '5e2a67161bf6ed1a0792e30eebb9837a6b111dfbae88e2296c2ebda60a97a618',
    blockheight: 7249,
    blockindex: 0,
    blocktime: 1660361951,
    txid: '5b984611886ce913dcc68aea72bd11633cae32bc7de734f86e6feba1706ba3fd',
    walletconflicts: [],
    time: 1660361951,
    timereceived: 1660361951,
    'bip125-replaceable': 'no'
  },
省略
]