bitcoin: 通过 rpc 请求节点数据

文章来自 简书

视频

配置文件

放在 /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_(...)
https://bitcoin.stackexchange.com/question...

本作品采用《CC 协议》,转载必须注明作者和本文链接
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!