{"id":3050,"date":"2022-08-12T12:09:52","date_gmt":"2022-08-12T03:09:52","guid":{"rendered":"https:\/\/blog.wsd.sh\/?p=3050"},"modified":"2022-08-16T04:35:29","modified_gmt":"2022-08-15T19:35:29","slug":"3050","status":"publish","type":"post","link":"https:\/\/blog.wsd.sh\/?p=3050","title":{"rendered":"<small>JSON-RPC Call: rpcauth<\/small>"},"content":{"rendered":"<p>1. Access with -rpcuser=eve<\/p>\n<pre>\r\n$ bitcoin-core.cli -rpcuser=eve  -rpcport=10008 getrpcinfo\r\n{\r\n  \"active_commands\": [\r\n    {\r\n      \"method\": \"getrpcinfo\",\r\n      \"duration\": 23\r\n    }\r\n  ],\r\n  \"logpath\": \"\/home\/user04\/dev\/eve\/regtest\/debug.log\"\r\n}\r\n$ bitcoin-core.cli -rpcuser=eve  -rpcport=10008 getbalance\r\n1.20000000\r\n<\/pre>\n<p>2. write settings to<br \/>\n<a href=\"https:\/\/jlopp.github.io\/bitcoin-core-rpc-auth-generator\/\">Bitcoin Core RPC Auth Config Generator<\/a><br \/>\n.\/snap\/bitcoin-core\/common\/.bitcoin\/bitcoin.conf<\/p>\n<pre>\r\n$ cat .\/snap\/bitcoin-core\/common\/.bitcoin\/bitcoin.conf\r\nregtest=1\r\ntxindex=1\r\nserver=1\r\nrpcuser=eve\r\nrpcpassword=066cd0b2d3e0b355b1cad790be2b9b0c$f87e338d94e838afcdfbf8e09a0db34c9f12e11bea055b7d616ae14b70f5aee9\r\nfallbackfee=0.002\r\n\r\n[regtest]\r\nrpcport=10008\r\n<\/pre>\n<p>3. Enter rpcpassword interactively<br \/>\n&#8211;user eve<\/p>\n<pre>\r\n$ curl --user eve --data-binary '{\"jsonrpc\": \"1.0\", \"id\": \"curltest\", \"method\": \"getrpcinfo\", \"params\": []}' -H 'content-type: text\/plain;' http:\/\/127.0.0.1:10008\/\r\nEnter host password for user 'eve':\r\n{\"result\":{\"active_commands\":[{\"method\":\"getrpcinfo\",\"duration\":35}],\"logpath\":\"\/home\/user04\/dev\/eve\/regtest\/debug.log\"},\"error\":null,\"id\":\"curltest\"}\r\n$ curl --user eve --data-binary '{\"jsonrpc\": \"1.0\", \"id\": \"curltest\", \"method\": \"getbalance\", \"params\": []}' -H 'content-type: text\/plain;'  http:\/\/127.0.0.1:10008\/\r\nEnter host password for user 'eve':\r\n{\"result\":1.20000000,\"error\":null,\"id\":\"curltest\"}\r\n<\/pre>\n<p>4.To specify rpcpassword with -u oprion, you need to add \\ before $ in rpcpassword<br \/>\n-ueve:066cd0b2d3e0b355b1cad790be2b9b0c\\$f87e338d94e838afcdfbf8e09a0db34c9f12e11bea055b7d616ae14b70f5aee9<\/p>\n<pre>\r\n$ curl -ueve:066cd0b2d3e0b355b1cad790be2b9b0c\\$f87e338d94e838afcdfbf8e09a0db34c9f12e11bea055b7d616ae14b70f5aee9 --data-binary '{\"jsonrpc\": \"1.0\", \"id\": \"curltest\", \"method\": \"getrpcinfo\", \"params\": []}' -H 'content-type:\r\ntext\/plain;'  http:\/\/127.0.0.1:10008\/\r\n{\"result\":{\"active_commands\":[{\"method\":\"getrpcinfo\",\"duration\":35}],\"logpath\":\"\/home\/user04\/dev\/eve\/regtest\/debug.log\"},\"error\":null,\"id\":\"curltest\"}\r\n$ 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\/\r\n{\"result\":1.20000000,\"error\":null,\"id\":\"curltest\"}\r\n<\/pre>\n<p>5. Set rpcuser:rcppassword to linux environment variable rpcauth<br \/>\n&#8211; rpcauth=&#8221;eve:066cd0b2d3e0b355b1cad790be2b9b0c$f87e338d94e838afcdfbf8e09a0db34c9f12e11bea055b7d616ae14b70f5aee9&#8243;<br \/>\n&#8211; In this case, you don&#8217;t need \\ before $<\/p>\n<pre>\r\n$ export rpcauth=\"eve:066cd0b2d3e0b355b1cad790be2b9b0c$f87e338d94e838afcdfbf8e09a0db34c9f12e11bea055b7d616ae14b70f5aee9\"\r\n$ curl -u \"${rpcauth}\" --data-binary '{\"jsonrpc\": \"1.0\", \"id\": \"curltest\", \"method\": \"getrpcinfo\", \"params\": []}' -H 'content-type: text\/plain;'  http:\/\/127.0.0.1:10008\/\r\n{\"result\":{\"active_commands\":[{\"method\":\"getrpcinfo\",\"duration\":21}],\"logpath\":\"\/home\/user04\/dev\/eve\/regtest\/debug.log\"},\"error\":null,\"id\":\"curltest\"}\r\n$ curl -u \"${rpcauth}\" --data-binary '{\"jsonrpc\": \"1.0\", \"id\": \"curltest\", \"method\": \"getbalance\", \"params\": []}' -H 'content-type: text\/plain;' http:\/\/127.0.0.1:10008\/\r\n{\"result\":1.20000000,\"error\":null,\"id\":\"curltest\"}\r\n<\/pre>\n<p>6. Get balance<br \/>\n&#8211; http:\/\/127.0.0.1:10008\/wallet\/EveWallet<\/p>\n<pre>\r\n$  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\r\n{\"result\":1.20000000,\"error\":null,\"id\":\"curltest\"}\r\n<\/pre>\n<p>7. Listtransactions<br \/>\n&#8211; http:\/\/127.0.0.1:10008\/wallet\/EveWallet<\/p>\n<pre>\r\n$  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 .\r\n  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\r\n                                 Dload  Upload   Total   Spent    Left  Speed\r\n100  2756  100  2676  100    80  2613k  80000 --:--:-- --:--:-- --:--:-- 2691k\r\n{\r\n  \"result\": [\r\n    {\r\n      \"address\": \"bcrt1qhnt96hwgaknldamh4dq3sm5ehqr7nq4capdfg5\",\r\n      \"category\": \"receive\",\r\n      \"amount\": 0.2,\r\n      \"label\": \"\",\r\n      \"vout\": 0,\r\n      \"confirmations\": 7,\r\n      \"blockhash\": \"219f1db53010ad9efcfc206aac2b76f1c1d22a334fe8cd7ac90e0319b975c332\",\r\n      \"blockheight\": 5893,\r\n      \"blockindex\": 1,\r\n      \"blocktime\": 1660260392,\r\n      \"txid\": \"90427f31cc602a5a139332b63fa93bc7479e4d5cdce6229f93c1ae42f4ed9cb1\",\r\n      \"walletconflicts\": [],\r\n      \"time\": 1660260362,\r\n      \"timereceived\": 1660260362,\r\n      \"bip125-replaceable\": \"no\"\r\n    },\r\n    \u7701\u7565\r\n  ],\r\n  \"error\": null,\r\n  \"id\": \"curltest\"\r\n}\r\n<\/pre>\n<p>8. Trabfer from eve to carol<br \/>\n&#8211; carol address : &#8220;bcrt1qhya07e4kejp7phxlnk7rckm5v9skh4jdzuesks&#8221;<br \/>\n&#8211; amount : 0.01<\/p>\n<pre>\r\n$  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 .\r\n{\r\n  \"result\": \"f2acd44c2a76703a867fed98cc5b0deccb72883d3c27e8b532843a3cd81309ac\",\r\n  \"error\": null,\r\n  \"id\": \"curltest\"\r\n}\r\n<\/pre>\n<p>9. Get balance<br \/>\n&#8211; carol side<br \/>\n&#8211; 10.80999386<\/p>\n<pre>\r\n$ bitcoin-core.cli -conf=\/home\/user03\/dev\/carol\/bitcoin.conf  getbalance\r\n10.80999386\r\n<\/pre>\n<p>10. Mining<br \/>\n&#8211; alice<\/p>\n<pre>\r\n$ bitcoin-core.cli -regtest -conf=\/home\/user02\/dev\/alice\/bitcoin.conf -datadir=. -rpcport=10001  generatetoaddress 1 bcrt1qht58vxn8avnek2ya3wfpyv65qml9q7l5a6lpek\r\n[\r\n  \"5a8d676756ad8d8763e450d4261650b196cbbdbe50790fedbec87872ccce2fd0\"\r\n]\r\n<\/pre>\n<p>11. Get balance<br \/>\n&#8211; carol side<br \/>\n&#8211; 10.81999386<\/p>\n<pre>\r\n$ bitcoin-core.cli -conf=\/home\/user03\/dev\/carol\/bitcoin.conf  getbalance\r\n10.81999386\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1. Access with -rpcuser=eve $ bitcoin-core.cli -rpcuser=eve -rpcport=10008 getrpcinfo { &#8220;active_commands&#8221;: [ {&#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\/3050"}],"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=3050"}],"version-history":[{"count":34,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/posts\/3050\/revisions"}],"predecessor-version":[{"id":3054,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/posts\/3050\/revisions\/3054"}],"wp:attachment":[{"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}