[转]bitcoin: 通过 rpc 请求节点数据
2024-08-27 03:18:29
本文转自: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
最新文章
- 使用CallableStatement的用法
- 蚁群算法简介(part3: 蚁群算法之更新信息素)
- GitHub 上一份很受欢迎的前端代码优化指南-强烈推荐收藏
- Mongo DB Study: first face with mongo DB
- Java笔试题解答和部分面试题
- html5 canvas 笔记三(绘制文本和图片)
- 【Python学习笔记】字典操作
- SmallDateTime时间范围检查
- html 学习笔记--基础篇
- JAVA中子类会不会继承父类的构造方法
- Java通配符解惑
- http无状态协议,cookie和session详解(一)
- focus()无效问题
- Python 中关于 round 函数的小坑
- Java io概述
- 教你用Windows自带工具给优盘/移动硬盘添加密码
- 容器平台选型的十大模式:Docker、DC/OS、K8S 谁与当先?【转】
- SAS DATA ENCODING 解决odbc乱码问题
- 关于解决java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoader问题
- 5. 集成学习(Ensemble Learning)GBDT