BSV(比特币SV)常用接口使用

BSV链常用接口使用

注:以下rpc接口测试均在开发网络完成

区块链API

挖矿类API

裸交易API

钱包类API

getblockcount

获取最新区块高度

  • 请求示例
bitcoin-cli -rpcuser=admin -rpcpassword=123456 -rpcport=18443 getblockcount

curl --user admin:123456 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockcount", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:18443/
getblockhash

获取指定高度区块的哈希

  • 请求参数
1.BlockHeight:区块高度
  • 请求示例
bitcoin-cli -rpcuser=admin -rpcpassword=123456 -rpcport=18443 getblockhash 121

curl --user admin:123456 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockhash", "params": [121] }' -H 'content-type: text/plain;' http://127.0.0.1:18443/
  • 返回参数
1.getblockhash:返回指定区块高度的区块哈希值
getblock

获取指定哈希的区块信息

  • 请求参数
1.HeaderHash:区块哈希
2.Format:结果格式,可选项为:0:串流格式;1:json格式(默认为1);2:json格式,同时解码区块中的交易
  • 请求示例
bitcoin-cli -rpcuser=admin -rpcpassword=123456 -rpcport=18443 getblock 1cd8f75a7961a1634f2420b9528e23c2e14f32555475f7280accfe04c1781755

curl --user admin:123456 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblock", "params": ["1cd8f75a7961a1634f2420b9528e23c2e14f32555475f7280accfe04c1781755"] }' -H 'content-type: text/plain;' http://127.0.0.1:18443/
  • 返回参数
getblock调用根据参数Format的不同返回值有所区别。

1.如果Format是0,那么返回的就是16进制字符串表示的序列化交易。
2.如果Format是1,那么返回的就是JSON对象,包括区块哈希,确认数,区块字节数等
3.如果Format是2,那么返回的JSON对象中tx数组成员是解码的交易对象
generatetoaddress

将挖矿之后的奖励发送至某个地址

  • 请求参数
1.Blocks:出块数量
2.Address:接收奖励的比特币的地址
3.Maxtries:最大重试次数,默认:1000000
  • 请求示例
bitcoin-cli -rpcuser=admin -rpcpassword=123456 -rpcport=18443 generatetoaddress 5 n3QDLbffvhM8zR9RbrtqeeyNFxo6AwfZ7V

curl --user admin:123456 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "generatetoaddress", "params": [5,"n2UP1otMG68tkyoXL4cWUacMPovMQ52mrt"] }' -H 'content-type: text/plain;' http://127.0.0.1:18443/
  • 返回参数
1.区块哈希:调用返回生成的区块头哈希数组
getrawtransaction

获取指定裸交易

  • 请求参数
1.TXID:要提取裸交易的交易ID
2.Format:返回格式,序列化字符串或JSON对象,false:返回序列化字符串(默认为false),true:返回解码后的JSON对象
  • 请求示例
bitcoin-cli -rpcuser=admin -rpcpassword=123456 -rpcport=18443 getrawtransaction b51cc630d326a6ba46fdb6ec7ce4f2a3800392dc811b4f08d315de5e75b783cc true

curl --user admin:123456 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getrawtransaction", "params": ["7ef526f8ed170b8bd4d7349d665b7e5266fca6213995cc0a9e901bce2f033d86",true] }' -H 'content-type: text/plain;' http://127.0.0.1:18443/
  • 返回参数
当参数Format的值为true时,返回的交易对象结构如下:
1.hex:序列化字符串
2.blockhash:所在区块的哈希值
3.confirmations:所在区块的确认数
4.time:所在区块的出块时间
5.blocktime:所在区块的出块时间,同上
decoderawtransaction

解码裸交易

  • 请求参数
1.SerializedTransaction:要解码的裸交易字符串
  • 请求示例
bitcoin-cli -rpcuser=admin -rpcpassword=123456 -rpcport=18443 decoderawtransaction 02000000011d0c5234b2694554f1420453efd7e6032e1cf1b4c2781b37695becd5804642cd000000006a47304402201a25a61354de4fb06301cf0eca6a8a3c5be53e69cf283dc27a51228639cf8da80220040003ccfc2e2bc57e50cb8aa556be4cad92b572d599dceb0c53427420ffd40c4121030a952c7ceba8a76e8e6f303be7900da9d54ea4a60afe696d97db2bb93d2a110efeffffff02b86a9dd0000000001976a91453743a88f76abc3b0f0d6ee1d1547cb2f2eb728188ac00ca9a3b000000001976a914f00c69db3a284b5c6db150fe4ebdaca164d8199c88ac66000000

curl --user admin:123456 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "decoderawtransaction", "params": ["02000000011d0c5234b2694554f1420453efd7e6032e1cf1b4c2781b37695becd5804642cd000000006a47304402201a25a61354de4fb06301cf0eca6a8a3c5be53e69cf283dc27a51228639cf8da80220040003ccfc2e2bc57e50cb8aa556be4cad92b572d599dceb0c53427420ffd40c4121030a952c7ceba8a76e8e6f303be7900da9d54ea4a60afe696d97db2bb93d2a110efeffffff02b86a9dd0000000001976a91453743a88f76abc3b0f0d6ee1d1547cb2f2eb728188ac00ca9a3b000000001976a914f00c69db3a284b5c6db150fe4ebdaca164d8199c88ac66000000"] }' -H 'content-type: text/plain;' http://127.0.0.1:18443/
  • 返回参数
成功解码后,decoderawtransaction返回一个JSON对象,否则返回null
getnewaddress

获取新地址

  • 请求参数
1.Account:新地址所属账户,可选,默认值:""
2.AddressType:地址类型,可以是legacy、p2sh-segwit和bech32,可以 使用-addresstype设置默认地址类型
  • 请求示例
bitcoin-cli -rpcuser=admin -rpcpassword=123456 -rpcport=18443 getnewaddress test 
n3QDLbffvhM8zR9RbrtqeeyNFxo6AwfZ7V
          
curl --user admin:123456 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getnewaddress", "params": ["test2"] }' -H 'content-type: text/plain;' http://127.0.0.1:18443/
{"result":"n2UP1otMG68tkyoXL4cWUacMPovMQ52mrt","error":null,"id":"curltest"}
  • 返回参数
1.getnewaddress:返回一个新的地址
getbalance

查看钱包中全部bsv可用余额

  • 请求参数
Confirmations: 可计入余额的UTXO所需要的最小确认数,可选,默认值:6
WatchOnlyIncl: 是否包含那些仅用于监测的地址,可选,默认值:true
  • 请求示例
bitcoin-cli -rpcuser=admin -rpcpassword=123456 -rpcport=18443 getbalance

curl --user admin:123456 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getbalance", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:18443/
  • 返回示例
1.返回以bsv为单位的钱包总余额
listaddressgroupings

显示bsv钱包中所有地址余额

  • 请求示例
bitcoin-cli -rpcuser=admin -rpcpassword=123456 -rpcport=18443 listaddressgroupings

curl --user admin:123456 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "listaddressgroupings", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:18443/
  • 返回参数
1.Address:地址
2.Balance:地址余额,不包含未确认收入
3.Account:地址关联的账户
sendtoaddress

发送金额至指定地址

  • 请求参数
1.ToAddress:接收地址
2.Amount:发送的比特币数量
3.Comment:备注文本,可选
4.CommentTo:备注接收人,可选
5.AutoFeeSubtract:是否自动扣除手续费,默认值:false
  • 请求示例
bitcoin-cli -rpcuser=admin -rpcpassword=123456 -rpcport=18443 sendtoaddress n2UP1otMG68tkyoXL4cWUacMPovMQ52mrt 5
cba38a79d6cd1c21d5d1f3e64bbd2049007082c967ab64061980db2ee1c22443

curl --user admin:123456 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "sendtoaddress", "params": ["n3QDLbffvhM8zR9RbrtqeeyNFxo6AwfZ7V",10] }' -H 'content-type: text/plain;' http://127.0.0.1:18443/
{"result":"7ef526f8ed170b8bd4d7349d665b7e5266fca6213995cc0a9e901bce2f033d86","error":null,"id":"curltest"}
  • 返回参数
返回该笔交易ID
gettransaction

获取钱包内交易的详细信息

  • 请求参数
TXID:要查看详情的交易ID
WatchOnlyIncl:是否包含watch-only地址
  • 请求示例
bitcoin-cli -rpcuser=admin -rpcpassword=123456 -rpcport=18443 gettransaction cba38a79d6cd1c21d5d1f3e64bbd2049007082c967ab64061980db2ee1c22443

curl --user admin:123456 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "gettransaction", "params": ["7ef526f8ed170b8bd4d7349d665b7e5266fca6213995cc0a9e901bce2f033d86"] }' -H 'content-type: text/plain;' http://127.0.0.1:18443/
  • 返回参数
1.amount:交易金额,正数表示该交易增加钱包余额,负数表示该交易减少钱包余额
2.fee:交易手续费,仅针对转出交易
3.confirmations:交易确认数,0表示未确认,-1表示存在冲突
4.generated:币基交易则该值为true
5.blockhash:交易所在区块的哈希
6.blockindex:交易所在区块的编号
7.blocktime:交易所在区块的unix时间
8.txid:交易ID
9.walletconflicts:冲突交易数组,成员为冲突交易的ID
10.timereceived:节点收到交易的unix时间
11.bip125-replacable:是否可替换交易
12.comment: 保存在钱包中的交易备注,
13.to:保存在钱包中的交易目标备注
14.details:输入输出详情数组,包括:send,receive,amount,fee
15.hex:串行序列化字符串
listreceivedbyaddress

获取各地址收到的比特币数量

  • 请求参数
Confirmations:计入统计结果的交易所需的最小确认数,默认值:1
IncludeEmpty:是否包含从未有收入的账户,可选,默认值:false
IncludeWatchOnly:是否包含watch-only地址,可选,默认值:false,详情可参见importaddress
  • 请求示例
bitcoin-cli -rpcuser=admin -rpcpassword=123456 -rpcport=18443 listreceivedbyaddress 6 true true

curl --user admin:123456 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "listreceivedbyaddress", "params": [6,true,true,"qqzgpjk7fsy5m4a90f22dnshlrhtsjf84sd0m4frvf"] }' -H 'content-type: text/plain;' http://127.0.0.1:18443/(被检测地址,)
  • 返回参数
1.nvolvesWatchOnly:是否是watch-only地址
2.address:地址
3.account:关联账户
4.amount:收到比特币总数量
5.confirmations:该地址最后一个交易的确认数
6.label:地址关联的账户
7.txids:向该地址支付过的交易数组,成员为交易ID
settxfee

settxfee 为钱包设置每kB的交易费用,将覆盖全局的-paytxfee命令行参数

  • 请求参数
1.FeePerKB:每千字节的手续费
  • 请求示例
bitcoin-cli -rpcuser=admin -rpcpassword=123456 -rpcport=18443 settxfee 0.00001

curl --user admin:123456 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "settxfee", "params": ["0.00002"] }' -H 'content-type: text/plain;' http://127.0.0.1:18443/
  • 返回参数
1.调用在成功时返回true。
dumpwallet

导出钱包文件为文本

  • 请求参数
Filename:导出的文件名
  • 请求示例
bitcoin-cli -rpcuser=admin -rpcpassword=123456 -rpcport=18443 dumpwallet /opt/wallet.txt

curl --user admin:123456 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "dumpwallet", "params": ["/opt/wallet.txt"] }' -H 'content-type: text/plain;' http://127.0.0.1:18443/
  • 返回参数
成功时,dumpwallet调用返回null,否则返回一个错误对象。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杰哥的技术杂货铺

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值