Litecoin(莱特币)常用RPC操作

创建多重签名

createmultisig调用创建一个P2SH多重签名地址

参数

1、MinSigs:消费发往该地址的UTXO所需要的最少签名数
2、KeysOrAddresses:公钥数组

返回值

调用返回生成的P2SH地址和赎回脚本,结果如下:
返回的地址为CashAddr address
1、address:地址
2、redeemScript:赎回脚本

代码示例

http://admin:[email protected]:18332
================
header:
Content-Type : application/json
body:
{   "jsonrpc": "2.0", 
    "id":"curltest", 
    "method": "createmultisig", 
    "params": [     2,
                [
                    "021184e6edabb488ed5dfba22ae40f027e36f8d3b24a7d3d8ff0c19726f37fe9a5",
                    "03b5842dbbcc3ae007bad1731a80b25050bb114d1058ddb909cf369e7c1db23457"
                ]
            ]
}
=============
response:
{
    "result": {
        "address": "bchtest:pp09qyp25zy43lwjycj2m5v8setx76zmxyc5nug8a4",
        "redeemScript": "5221021184e6edabb488ed5dfba22ae40f027e36f8d3b24a7d3d8ff0c19726f37fe9a52103b5842dbbcc3ae007bad1731a80b25050bb114d1058ddb909cf369e7c1db2345752ae"
    },
    "error": null,
    "id": "curltest"
}

交易广播

sendrawtransaction调用验证指定交易并将其广播到P2P网络中。

参数

1、Transaction:序列化的交易码流,16进制字符串
2、AllowHighFees:是否允许高额手续费,可选,默认值:false

返回值

成功时sendrawtransaction调用返回交易ID,否则返回错误信息。

代码示例

http://admin:[email protected]:18332
================
header:
Content-Type : application/json
body:
{   "jsonrpc": "2.0", 
    "id":"curltest", 
    "method": "sendrawtransaction", 
    "params": [
           "010000000180784aa0cc6469e5e7a7e1bfcad98a1207ea1f4bfe2966403dcc6c0b977bccac010000006b483045022100e3b5b26adbe806d873329dcef823e8da61d37bf6c71094c7a932f328129cc071022005c77bfac7b668fd590225edeaebd7ee46f9b9bf4749b2377a3281e9b9eaeee5012102658a0ca5656db744b3c79d230cf3b09ac8905711db8fa59f7cdb56bb95ee1747ffffffff02809698000000000017a914215ca3a79ce4c7d3e1d587d9483fbf5461bf91ff8720de230b000000001976a914ee308491558158bb5e1478bb5163211f3981687c88ac00000000"
            ]
}
=================
response:
{
    "result": "944c9f40d62bcba63af91cf5b36665e2d792791d15737529d307b09e2d881ef3",
    "error": null,
    "id": "curltest"
}

创建交易

createrawtransaction调用创建一个未签名的序列化交易,该交易可以将一个UTXO 转让给指定的P2PKH地址或P2SH地址。该交易不会存储在钱包里,也不会发送到P2P网络中。

参数

1、Inputs:交易输入数组,每个成员对象的结构如下:
  a、txid:UTXO的交易id
  b、vout:UTXO的输出序号
  c、Sequence:序列号,可选
2、Outputs:交易输出对象,键为地址,值为金额 eg:{ "mgnucj8nYqdrPFh2JfZSB1NmUThUGnmsqe": 0.13 }
3、Locktime:声明该交易生效的最早时间,可选

返回值

createrawtransaction调用返回生成的未签名交易的序列化字符串。

代码示例

http://admin:[email protected]:18332
================
header:
Content-Type : application/json
body:
{   "jsonrpc": "2.0", 
    "id":"curltest", 
    "method": "createrawtransaction", 
    "params": [
            [{"txid":"944c9f40d62bcba63af91cf5b36665e2d792791d15737529d307b09e2d881ef3","vout":0}],
            {"QPePPKTYfei4iP1R7JtdpTLBzhAUtEosdh":0.1, "n3EPEngegPGeDMmpey4U2quqX79usDRKqR":0.0989}
            ]
}
=================
response:
{
    "result": "0200000001f31e882d9eb007d3297573151d7992d7e26566b3f51cf93aa6cb2bd6409f4c940000000000ffffffff02809698000000000017a914215ca3a79ce4c7d3e1d587d9483fbf5461bf91ff87d0e89600000000001976a914ee308491558158bb5e1478bb5163211f3981687c88ac00000000",
    "error": null,
    "id": "curltest"
}

获取交易详情

getrawtransaction调用提取指定id的裸交易字符串或解码后的JSON对象\
由于默认情况下,节点仅保存部分交易的完整数据(例如包含UTXO的交易,以及 你自己发起的交易),
因此该调用可能在提取历史交易时会失败,除非在 启动节点时,使用了-txindex=1选项。

参数

1、TXID:要提取裸交易的ID
2、Format:返回格式,序列化字符串或JSON对象,
    false:返回序列化字符串
    true:返回解码后的JSON对象

返回值

getrawtransaction调用返回指定交易指定格式的结果,如果未找到则返回null。 当参数Format的值为true时,返回的交易对象结构如下:
1、hex:序列化字符串
2、blockhash:所在区块的哈希值
3、confirmations:所在区块的确认数
4、time:所在区块的出块时间
5、blocktime:所在区块的出块时间,同上

代码示例

http://admin:[email protected]:18332
================
header:
Content-Type : application/json
body:
{   "jsonrpc": "2.0", 
    "id":"curltest", 
    "method": "getrawtransaction", 
    "params": [
            "944c9f40d62bcba63af91cf5b36665e2d792791d15737529d307b09e2d881ef3",
            true
            ]
}
=================
response:
{
    "result": {
        "txid": "944c9f40d62bcba63af91cf5b36665e2d792791d15737529d307b09e2d881ef3",
        "hash": "944c9f40d62bcba63af91cf5b36665e2d792791d15737529d307b09e2d881ef3",
        "version": 1,
        "size": 224,
        "vsize": 224,
        "locktime": 0,
        "vin": [
            {
                "txid": "accc7b970b6ccc3d406629fe4b1fea07128ad9cabfe1a7e7e56964cca04a7880",
                "vout": 1,
                "scriptSig": {
                    "asm": "3045022100e3b5b26adbe806d873329dcef823e8da61d37bf6c71094c7a932f328129cc071022005c77bfac7b668fd590225edeaebd7ee46f9b9bf4749b2377a3281e9b9eaeee5[ALL] 02658a0ca5656db744b3c79d230cf3b09ac8905711db8fa59f7cdb56bb95ee1747",
                    "hex": "483045022100e3b5b26adbe806d873329dcef823e8da61d37bf6c71094c7a932f328129cc071022005c77bfac7b668fd590225edeaebd7ee46f9b9bf4749b2377a3281e9b9eaeee5012102658a0ca5656db744b3c79d230cf3b09ac8905711db8fa59f7cdb56bb95ee1747"
                },
                "sequence": 4294967295
            }
        ],
        "vout": [
            {
                "value": 0.1,
                "n": 0,
                "scriptPubKey": {
                    "asm": "OP_HASH160 215ca3a79ce4c7d3e1d587d9483fbf5461bf91ff OP_EQUAL",
                    "hex": "a914215ca3a79ce4c7d3e1d587d9483fbf5461bf91ff87",
                    "reqSigs": 1,
                    "type": "scripthash",
                    "addresses": [
                        "QPePPKTYfei4iP1R7JtdpTLBzhAUtEosdh"
                    ]
                }
            },
            {
                "value": 1.869,
                "n": 1,
                "scriptPubKey": {
                    "asm": "OP_DUP OP_HASH160 ee308491558158bb5e1478bb5163211f3981687c OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a914ee308491558158bb5e1478bb5163211f3981687c88ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash",
                    "addresses": [
                        "n3EPEngegPGeDMmpey4U2quqX79usDRKqR"
                    ]
                }
            }
        ],
        "hex": "010000000180784aa0cc6469e5e7a7e1bfcad98a1207ea1f4bfe2966403dcc6c0b977bccac010000006b483045022100e3b5b26adbe806d873329dcef823e8da61d37bf6c71094c7a932f328129cc071022005c77bfac7b668fd590225edeaebd7ee46f9b9bf4749b2377a3281e9b9eaeee5012102658a0ca5656db744b3c79d230cf3b09ac8905711db8fa59f7cdb56bb95ee1747ffffffff02809698000000000017a914215ca3a79ce4c7d3e1d587d9483fbf5461bf91ff8720de230b000000001976a914ee308491558158bb5e1478bb5163211f3981687c88ac00000000",
        "blockhash": "0ee91a45ea39197f00fb3be2abf70a8659138bdf703ff3dd2d093f081babb33f",
        "confirmations": 1,
        "time": 1554881963,
        "blocktime": 1554881963
    },
    "error": null,
    "id": "curltest"
}

赎回脚本序列化解码

decodescript调用解码一个P2SH赎回脚本。

参数

1、RedeemScript:要解码的赎回脚本,16进制字符串

返回值

decodescript调用返回解码后的脚本对象,结构如下:
1、asm:采用助记符表示的脚本
2、type:脚本类型,可以是:
  a、pubkey:P2SH里的P2PK脚本
  b、pubkeyhash:P2SH里的P2PKH脚本
  c、multisig:P2SH里的多重签名脚本
  d、nonstandard:非标脚本
3、reqSigs:需要的签名数量
4、addresses:脚本中使用的地址数组
5、p2sh:该赎回脚本的P2SH地址

代码示例

http://admin:[email protected]:18332
================
header:
Content-Type : application/json
body:
{
 "jsonrpc": "2.0",
 "method": "decodescript",
 "params": ["010000000180784aa0cc6469e5e7a7e1bfcad98a1207ea1f4bfe2966403dcc6c0b977bccac010000006b483045022100e3b5b26adbe806d873329dcef823e8da61d37bf6c71094c7a932f328129cc071022005c77bfac7b668fd590225edeaebd7ee46f9b9bf4749b2377a3281e9b9eaeee5012102658a0ca5656db744b3c79d230cf3b09ac8905711db8fa59f7cdb56bb95ee1747ffffffff02809698000000000017a914215ca3a79ce4c7d3e1d587d9483fbf5461bf91ff8720de230b000000001976a914ee308491558158bb5e1478bb5163211f3981687c88ac00000000"] 
}
=================
response:
{
    "result": {
        "asm": "0 0 0 0 OP_OVER a0cc6469e5e7a7e1bfcad98a1207ea1f4bfe2966403dcc6c0b977bccac010000006b483045022100e3b5b26adbe806d873329dcef823e8da61d37bf6c71094c7a932f328129cc0710220 c77bfac7b6 OP_ENDIF OP_UNKNOWN 9 -27941 OP_UNKNOWN OP_UNKNOWN OP_UNKNOWN OP_UNKNOWN f9b9bf4749b2377a3281e9b9eaeee5012102658a0ca5656db744b3c79d230cf3b09ac8905711db8fa59f7cdb56bb95ee1747ffffffff02809698000000000017a914215ca3a7 OP_NUMEQUAL OP_UNKNOWN OP_UNKNOWN OP_UNKNOWN OP_UNKNOWN OP_UNKNOWN OP_EQUAL OP_UNKNOWN [error]",
        "type": "nonstandard",
        "p2sh": "QhZfmnQuom4qD88g3tepkkMG67NtXe9Tnp"
    },
    "error": null,
    "id": null
}

交易序列化解码

decoderawtransaction调用将一个序列化的交易字符串解码为JSON对象。

参数

1、SerializedTransaction:要解码的裸交易字符串

返回值

成功解码后,decoderawtransaction返回一个JSON对象,否则返回`null`。

代码示例

http://admin:[email protected]:18332
================
header:
Content-Type : application/json
body:
{
 "jsonrpc": "2.0",
 "method": "decoderawtransaction",
 "params": ["010000000180784aa0cc6469e5e7a7e1bfcad98a1207ea1f4bfe2966403dcc6c0b977bccac010000006b483045022100e3b5b26adbe806d873329dcef823e8da61d37bf6c71094c7a932f328129cc071022005c77bfac7b668fd590225edeaebd7ee46f9b9bf4749b2377a3281e9b9eaeee5012102658a0ca5656db744b3c79d230cf3b09ac8905711db8fa59f7cdb56bb95ee1747ffffffff02809698000000000017a914215ca3a79ce4c7d3e1d587d9483fbf5461bf91ff8720de230b000000001976a914ee308491558158bb5e1478bb5163211f3981687c88ac00000000"] 
}
=================
response:
{
    "result": {
        "txid": "944c9f40d62bcba63af91cf5b36665e2d792791d15737529d307b09e2d881ef3",
        "hash": "944c9f40d62bcba63af91cf5b36665e2d792791d15737529d307b09e2d881ef3",
        "version": 1,
        "size": 224,
        "vsize": 224,
        "locktime": 0,
        "vin": [
            {
                "txid": "accc7b970b6ccc3d406629fe4b1fea07128ad9cabfe1a7e7e56964cca04a7880",
                "vout": 1,
                "scriptSig": {
                    "asm": "3045022100e3b5b26adbe806d873329dcef823e8da61d37bf6c71094c7a932f328129cc071022005c77bfac7b668fd590225edeaebd7ee46f9b9bf4749b2377a3281e9b9eaeee5[ALL] 02658a0ca5656db744b3c79d230cf3b09ac8905711db8fa59f7cdb56bb95ee1747",
                    "hex": "483045022100e3b5b26adbe806d873329dcef823e8da61d37bf6c71094c7a932f328129cc071022005c77bfac7b668fd590225edeaebd7ee46f9b9bf4749b2377a3281e9b9eaeee5012102658a0ca5656db744b3c79d230cf3b09ac8905711db8fa59f7cdb56bb95ee1747"
                },
                "sequence": 4294967295
            }
        ],
        "vout": [
            {
                "value": 0.1,
                "n": 0,
                "scriptPubKey": {
                    "asm": "OP_HASH160 215ca3a79ce4c7d3e1d587d9483fbf5461bf91ff OP_EQUAL",
                    "hex": "a914215ca3a79ce4c7d3e1d587d9483fbf5461bf91ff87",
                    "reqSigs": 1,
                    "type": "scripthash",
                    "addresses": [
                        "QPePPKTYfei4iP1R7JtdpTLBzhAUtEosdh"
                    ]
                }
            },
            {
                "value": 1.869,
                "n": 1,
                "scriptPubKey": {
                    "asm": "OP_DUP OP_HASH160 ee308491558158bb5e1478bb5163211f3981687c OP_EQUALVERIFY OP_CHECKSIG",
                    "hex": "76a914ee308491558158bb5e1478bb5163211f3981687c88ac",
                    "reqSigs": 1,
                    "type": "pubkeyhash",
                    "addresses": [
                        "n3EPEngegPGeDMmpey4U2quqX79usDRKqR"
                    ]
                }
            }
        ]
    },
    "error": null,
    "id": null
}

你可能感兴趣的:(Litecoin(莱特币)常用RPC操作)