[转]bitcoin: 通过 rpc 请求节点数据

本文转自:https://laravel-china.org/index.php/articles/8919/bitcoin-requests-node-data-through-rpc

文章来自本人的 简书

俺滴围脖 https://weibo.com/liuningtw

配置文件

放在 /mnt/bitcoin 目录下

#  /mnt/bitcoin/bitcoin.conf 
server=1
daemon=1
rpcthreads=10
txindex=1
rpcuser=bitcoin
rpcpassword=12345

运行节点

bitcoind -datadir=/mnt/bitcoin # 确保有/mnt/bitcoin/bitcoin.conf

curl

curl --user bitcoin:12345 -H 'content-type:text/plain;' http://127.0.0.1:8332/
--data-binary '{"jsonrpc":"1.0","id":"1","method":"getblockhash","params":[1]}'

{
  "result": "00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048",
  "error": null,
  "id": "1"
}

python script

import json
import requests

url = "http://127.0.0.1:8332/"
auth=("bitcoin", "12345")
payload = json.dumps({"method": 'getblockhash', "params": [1] })

response = requests.request("POST", url, data=payload, auth=auth)
print(response.text)

参考:

https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)
https://bitcoin.stackexchange.com/questions/19665/json-rpc-via-curl

 

posted on 2019-01-03 16:27  freeliver54  阅读(...)  评论(... 编辑 收藏

导航