问题描述:
按照网上和官方手册部署好bitcoin节点,启动测试网,
bitcoind -conf=/usr/local/bitcoin/conf/bitcoin.conf -testnet-daemon
仅能在本地使用curl访问api,例如:
# curl --user USER:PWD -H 'content-type:text/plain;' http://127.0.0.1:18332/ --data-binary '{"jsonrpc":"1.0","id":"1","method":"getblockhash","params":[1]}'
{"result":"00000000b873e79784647a6c82962c70d228557d24a747ea4d1b8bbe878e1206","error":null,"id":"1"}
从外部访问则返回:
curl: (52) Empty reply from server。
在bitcoin.conf文件里添加如下参数后:
rpcbind=192.168.x.x
rpcport=18333
重启,会报错【Error: Config setting for -rpcbind only applied on test network when in [test] section.】
解决方法:在参数上面添加[test]。
[test]
rpcbind=192.168.x.x
rpcport=18333
rpcallowip=0.0.0.0/0 # 允许任意地址访问
# curl --user USER:PWD-H 'content-type:text/plain;' http://公网ip:18333/ --data-binary '{"jsonrpc":"1.0","id":"1","method":"getblockhash","params":[1]}'
{"result":"00000000b873e79784647a6c82962c70d228557d24a747ea4d1b8bbe878e1206","error":null,"id":"1"}
参考:
https://bitcoin.stackexchange.com/questions/77607/cant-specify-rpcport-for-testnet