JSON-RPC Call: rpcauth

1. Access with -rpcuser=eve

$ bitcoin-core.cli -rpcuser=eve  -rpcport=10008 getrpcinfo
{
  "active_commands": [
    {
      "method": "getrpcinfo",
      "duration": 23
    }
  ],
  "logpath": "/home/user04/dev/eve/regtest/debug.log"
}
$ bitcoin-core.cli -rpcuser=eve  -rpcport=10008 getbalance
1.20000000

2. write settings to
Bitcoin Core RPC Auth Config Generator
./snap/bitcoin-core/common/.bitcoin/bitcoin.conf

$ cat ./snap/bitcoin-core/common/.bitcoin/bitcoin.conf
regtest=1
txindex=1
server=1
rpcuser=eve
rpcpassword=066cd0b2d3e0b355b1cad790be2b9b0c$f87e338d94e838afcdfbf8e09a0db34c9f12e11bea055b7d616ae14b70f5aee9
fallbackfee=0.002

[regtest]
rpcport=10008

3. Enter rpcpassword interactively
–user eve

$ curl --user eve --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getrpcinfo", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:10008/
Enter host password for user 'eve':
{"result":{"active_commands":[{"method":"getrpcinfo","duration":35}],"logpath":"/home/user04/dev/eve/regtest/debug.log"},"error":null,"id":"curltest"}
$ curl --user eve --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getbalance", "params": []}' -H 'content-type: text/plain;'  http://127.0.0.1:10008/
Enter host password for user 'eve':
{"result":1.20000000,"error":null,"id":"curltest"}

4.To specify rpcpassword with -u oprion, you need to add \ before $ in rpcpassword
-ueve:066cd0b2d3e0b355b1cad790be2b9b0c\$f87e338d94e838afcdfbf8e09a0db34c9f12e11bea055b7d616ae14b70f5aee9

$ curl -ueve:066cd0b2d3e0b355b1cad790be2b9b0c\$f87e338d94e838afcdfbf8e09a0db34c9f12e11bea055b7d616ae14b70f5aee9 --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getrpcinfo", "params": []}' -H 'content-type:
text/plain;'  http://127.0.0.1:10008/
{"result":{"active_commands":[{"method":"getrpcinfo","duration":35}],"logpath":"/home/user04/dev/eve/regtest/debug.log"},"error":null,"id":"curltest"}
$ curl -ueve:066cd0b2d3e0b355b1cad790be2b9b0c\$f87e338d94e838afcdfbf8e09a0db34c9f12e11bea055b7d616ae14b70f5aee9 --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getbalance", "params": []}' -H 'content-type:text/plain;'  http://127.0.0.1:10008/
{"result":1.20000000,"error":null,"id":"curltest"}

5. Set rpcuser:rcppassword to linux environment variable rpcauth
– rpcauth=”eve:066cd0b2d3e0b355b1cad790be2b9b0c$f87e338d94e838afcdfbf8e09a0db34c9f12e11bea055b7d616ae14b70f5aee9″
– In this case, you don’t need \ before $

$ export rpcauth="eve:066cd0b2d3e0b355b1cad790be2b9b0c$f87e338d94e838afcdfbf8e09a0db34c9f12e11bea055b7d616ae14b70f5aee9"
$ curl -u "${rpcauth}" --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getrpcinfo", "params": []}' -H 'content-type: text/plain;'  http://127.0.0.1:10008/
{"result":{"active_commands":[{"method":"getrpcinfo","duration":21}],"logpath":"/home/user04/dev/eve/regtest/debug.log"},"error":null,"id":"curltest"}
$ curl -u "${rpcauth}" --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getbalance", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:10008/
{"result":1.20000000,"error":null,"id":"curltest"}

6. Get balance
– http://127.0.0.1:10008/wallet/EveWallet

$  curl -u "${bitcoinauth}" --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getbalance", "params": []}' -H 'content-type: text/plain;'  http://127.0.0.1:10008/wallet/EveWallet
{"result":1.20000000,"error":null,"id":"curltest"}

7. Listtransactions
– http://127.0.0.1:10008/wallet/EveWallet

$  curl -u "${bitcoinauth}" --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "listtransactions", "params": []}' -H 'content-type: text/plain;'  http://127.0.0.1:10008/wallet/EveWallet | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2756  100  2676  100    80  2613k  80000 --:--:-- --:--:-- --:--:-- 2691k
{
  "result": [
    {
      "address": "bcrt1qhnt96hwgaknldamh4dq3sm5ehqr7nq4capdfg5",
      "category": "receive",
      "amount": 0.2,
      "label": "",
      "vout": 0,
      "confirmations": 7,
      "blockhash": "219f1db53010ad9efcfc206aac2b76f1c1d22a334fe8cd7ac90e0319b975c332",
      "blockheight": 5893,
      "blockindex": 1,
      "blocktime": 1660260392,
      "txid": "90427f31cc602a5a139332b63fa93bc7479e4d5cdce6229f93c1ae42f4ed9cb1",
      "walletconflicts": [],
      "time": 1660260362,
      "timereceived": 1660260362,
      "bip125-replaceable": "no"
    },
    省略
  ],
  "error": null,
  "id": "curltest"
}

8. Trabfer from eve to carol
– carol address : “bcrt1qhya07e4kejp7phxlnk7rckm5v9skh4jdzuesks”
– amount : 0.01

$  curl -s -u "${bitcoinauth}" --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "sendtoaddress", "params": ["bcrt1qhya07e4kejp7phxlnk7rckm5v9skh4jdzuesks",0.01]}' -H 'content-type: text/plain;'  http://127.0.0.1:10008/wallet/EveWallet | jq .
{
  "result": "f2acd44c2a76703a867fed98cc5b0deccb72883d3c27e8b532843a3cd81309ac",
  "error": null,
  "id": "curltest"
}

9. Get balance
– carol side
– 10.80999386

$ bitcoin-core.cli -conf=/home/user03/dev/carol/bitcoin.conf  getbalance
10.80999386

10. Mining
– alice

$ bitcoin-core.cli -regtest -conf=/home/user02/dev/alice/bitcoin.conf -datadir=. -rpcport=10001  generatetoaddress 1 bcrt1qht58vxn8avnek2ya3wfpyv65qml9q7l5a6lpek
[
  "5a8d676756ad8d8763e450d4261650b196cbbdbe50790fedbec87872ccce2fd0"
]

11. Get balance
– carol side
– 10.81999386

$ bitcoin-core.cli -conf=/home/user03/dev/carol/bitcoin.conf  getbalance
10.81999386