Dash对接

本文详细展示了如何使用Dash的RPC命令行工具进行交易操作,包括获取未花费交易输出(UTXO)、创建交易、签名交易及广播交易的过程。示例中涉及了交易输入、输出的设置,以及私钥的使用,最终成功发送了一个交易并查询了其状态。
摘要由CSDN通过智能技术生成
  • 测试地址和私钥
yav18uegWthEs6JgABm94PDsgLkYW3CDnK	
cQkSMkARdyVsGU5ZkXEUvZQXQw5m2hGitcP31HFUHL8ZfXCFj9Rn
  • 获取utxo
 {
    "txid": "61cd02b672fac992d6b411024c137667ae209ebae1f836333c1635e5ab5819be",
    "vout": 0,
    "address": "yav18uegWthEs6JgABm94PDsgLkYW3CDnK",
    "account": "user",
    "scriptPubKey": "76a914a01adb3a7258c9e95bc4d2f755ad36e8f652cfc588ac",
    "amount": 1.00000000,
    "confirmations": 75223,
    "spendable": false,
    "solvable": false,
    "safe": true,
    "ps_rounds": -2
  }

  • createrawtransaction
[root@blockchain-node2 rpc_shell]# dashtest help createrawtransaction
createrawtransaction [{"txid":"id","vout":n},...] {"address":amount,"data":"hex",...} ( locktime )

Create a transaction spending the given inputs and creating new outputs.
Outputs can be addresses or data.
Returns hex-encoded raw transaction.
Note that the transaction's inputs are not signed, and
it is not stored in the wallet or transmitted to the network.

Arguments:
1. "inputs"                (array, required) A json array of json objects
     [
       {
         "txid":"id",    (string, required) The transaction id
         "vout":n,         (numeric, required) The output number
         "sequence":n      (numeric, optional) The sequence number
       } 
       ,...
     ]
2. "outputs"               (object, required) a json object with outputs
    {
      "address": x.xxx,    (numeric or string, required) The key is the dash address, the numeric value (can be string) is the DASH amount
      "data": "hex"      (string, required) The key is "data", the value is hex encoded data
      ,...
    }
3. locktime                  (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs

Result:
"transaction"              (string) hex string of the transaction

Examples:
> dash-cli createrawtransaction "[{\"txid\":\"myid\",\"vout\":0}]" "{\"address\":0.01}"
> dash-cli createrawtransaction "[{\"txid\":\"myid\",\"vout\":0}]" "{\"data\":\"00010203\"}"
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "createrawtransaction", "params": ["[{\"txid\":\"myid\",\"vout\":0}]", "{\"address\":0.01}"] }' -H 'content-type: text/plain;' http://127.0.0.1:19998/
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "createrawtransaction", "params": ["[{\"txid\":\"myid\",\"vout\":0}]", "{\"data\":\"00010203\"}"] }' -H 'content-type: text/plain;' http://127.0.0.1:19998/

[root@blockchain-node2 rpc_shell]# 





  • 创建交易

[root@blockchain-node2 rpc_shell]# 
[root@blockchain-node2 rpc_shell]# dashtest createrawtransaction "[{\"txid\":\"61cd02b672fac992d6b411024c137667ae209ebae1f836333c1635e5ab5819be\",\"vout\":0}]"  "{\"yWJrucVQooDTvJCNd8ki2hV2PRqreEQbCe\":0.01, \"yav18uegWthEs6JgABm94PDsgLkYW3CDnK\":0.8999}"
0200000001be1958abe535163c3336f8e1ba9e20ae6776134c0211b4d692c9fa72b602cd610000000000ffffffff0240420f00000000001976a9146d94ecd5fb5762fd63fe532e56b917bc210240d388ac70235d05000000001976a914a01adb3a7258c9e95bc4d2f755ad36e8f652cfc588ac00000000
[root@blockchain-node2 rpc_shell]#

  • signrawtransaction
[root@blockchain-node2 rpc_shell]#  dashtest help signrawtransaction
signrawtransaction "hexstring" ( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...] ["privatekey1",...] sighashtype )

Sign inputs for raw transaction (serialized, hex-encoded).
The second optional argument (may be null) is an array of previous transaction outputs that
this transaction depends on but may not yet be in the block chain.
The third optional argument (may be null) is an array of base58-encoded private
keys that, if given, will be the only keys used to sign the transaction.


Arguments:
1. "hexstring"     (string, required) The transaction hex string
2. "prevtxs"       (string, optional) An json array of previous dependent transaction outputs
     [               (json array of json objects, or 'null' if none provided)
       {
         "txid":"id",             (string, required) The transaction id
         "vout":n,                  (numeric, required) The output number
         "scriptPubKey": "hex",   (string, required) script key
         "redeemScript": "hex"    (string, required for P2SH) redeem script
       }
       ,...
    ]
3. "privkeys"     (string, optional) A json array of base58-encoded private keys for signing
    [                  (json array of strings, or 'null' if none provided)
      "privatekey"   (string) private key in base58-encoding
      ,...
    ]
4. "sighashtype"     (string, optional, default=ALL) The signature hash type. Must be one of
       "ALL"
       "NONE"
       "SINGLE"
       "ALL|ANYONECANPAY"
       "NONE|ANYONECANPAY"
       "SINGLE|ANYONECANPAY"

Result:
{
  "hex" : "value",           (string) The hex-encoded raw transaction with signature(s)
  "complete" : true|false,   (boolean) If the transaction has a complete set of signatures
  "errors" : [                 (json array of objects) Script verification errors (if there are any)
    {
      "txid" : "hash",           (string) The hash of the referenced, previous transaction
      "vout" : n,                (numeric) The index of the output to spent and used as input
      "scriptSig" : "hex",       (string) The hex-encoded signature script
      "sequence" : n,            (numeric) Script sequence number
      "error" : "text"           (string) Verification or signing error related to the input
    }
    ,...
  ]
}

Examples:
> dash-cli signrawtransaction "myhex"
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "signrawtransaction", "params": ["myhex"] }' -H 'content-type: text/plain;' http://127.0.0.1:19998/

[root@blockchain-node2 rpc_shell]# 

  • 签名交易

[root@blockchain-node2 rpc_shell]# 
[root@blockchain-node2 rpc_shell]# dashtest  signrawtransaction  "0200000001be1958abe535163c3336f8e1ba9e20ae6776134c0211b4d692c9fa72b602cd610000000000ffffffff0240420f00000000001976a9146d94ecd5fb5762fd63fe532e56b917bc210240d388ac70235d05000000001976a914a01adb3a7258c9e95bc4d2f755ad36e8f652cfc588ac00000000"  "[{\"txid\": \"61cd02b672fac992d6b411024c137667ae209ebae1f836333c1635e5ab5819be\",\"vout\": 0,\"scriptPubKey\": \"76a914a01adb3a7258c9e95bc4d2f755ad36e8f652cfc588ac\",\"amount\": 1.00000000}]"  "[\"cQkSMkARdyVsGU5ZkXEUvZQXQw5m2hGitcP31HFUHL8ZfXCFj9Rn\"]"
{
  "hex": "0200000001be1958abe535163c3336f8e1ba9e20ae6776134c0211b4d692c9fa72b602cd61000000006b483045022100d6f54722127c3f88c3598c03fdeecc12c20e84976e8e3a926a5474fa455ac5d5022013ffccadea259d40f345948c169b8cd157b37ba29d2667742b6b32d10472d34c0121039dcde50ee13625cadad533413e30b6c8e3015475a0e7b2ead52452b08df2ec21ffffffff0240420f00000000001976a9146d94ecd5fb5762fd63fe532e56b917bc210240d388ac70235d05000000001976a914a01adb3a7258c9e95bc4d2f755ad36e8f652cfc588ac00000000",
  "complete": true
}
[root@blockchain-node2 rpc_shell]# 
[root@blockchain-node2 rpc_shell]# 

  • 广播交易

[root@blockchain-node2 rpc_shell]# 
[root@blockchain-node2 rpc_shell]# dashtest sendrawtransaction 0200000001be1958abe535163c3336f8e1ba9e20ae6776134c0211b4d692c9fa72b602cd61000000006b483045022100d6f54722127c3f88c3598c03fdeecc12c20e84976e8e3a926a5474fa455ac5d5022013ffccadea259d40f345948c169b8cd157b37ba29d2667742b6b32d10472d34c0121039dcde50ee13625cadad533413e30b6c8e3015475a0e7b2ead52452b08df2ec21ffffffff0240420f00000000001976a9146d94ecd5fb5762fd63fe532e56b917bc210240d388ac70235d05000000001976a914a01adb3a7258c9e95bc4d2f755ad36e8f652cfc588ac00000000
47807605402ee3fe2db61bb40350c358d829e4b09e3562da2717ad71fbc8812e
[root@blockchain-node2 rpc_shell]# 


  • 交易查询

[root@blockchain-node2 rpc_shell]# dashtest getrawtransaction 47807605402ee3fe2db61bb40350c358d829e4b09e3562da2717ad71fbc8812e true
{
  "hex": "0200000001be1958abe535163c3336f8e1ba9e20ae6776134c0211b4d692c9fa72b602cd61000000006b483045022100d6f54722127c3f88c3598c03fdeecc12c20e84976e8e3a926a5474fa455ac5d5022013ffccadea259d40f345948c169b8cd157b37ba29d2667742b6b32d10472d34c0121039dcde50ee13625cadad533413e30b6c8e3015475a0e7b2ead52452b08df2ec21ffffffff0240420f00000000001976a9146d94ecd5fb5762fd63fe532e56b917bc210240d388ac70235d05000000001976a914a01adb3a7258c9e95bc4d2f755ad36e8f652cfc588ac00000000",
  "txid": "47807605402ee3fe2db61bb40350c358d829e4b09e3562da2717ad71fbc8812e",
  "size": 226,
  "version": 2,
  "type": 0,
  "locktime": 0,
  "vin": [
    {
      "txid": "61cd02b672fac992d6b411024c137667ae209ebae1f836333c1635e5ab5819be",
      "vout": 0,
      "scriptSig": {
        "asm": "3045022100d6f54722127c3f88c3598c03fdeecc12c20e84976e8e3a926a5474fa455ac5d5022013ffccadea259d40f345948c169b8cd157b37ba29d2667742b6b32d10472d34c[ALL] 039dcde50ee13625cadad533413e30b6c8e3015475a0e7b2ead52452b08df2ec21",
        "hex": "483045022100d6f54722127c3f88c3598c03fdeecc12c20e84976e8e3a926a5474fa455ac5d5022013ffccadea259d40f345948c169b8cd157b37ba29d2667742b6b32d10472d34c0121039dcde50ee13625cadad533413e30b6c8e3015475a0e7b2ead52452b08df2ec21"
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.01000000,
      "valueSat": 1000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 6d94ecd5fb5762fd63fe532e56b917bc210240d3 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a9146d94ecd5fb5762fd63fe532e56b917bc210240d388ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "yWJrucVQooDTvJCNd8ki2hV2PRqreEQbCe"
        ]
      }
    }, 
    {
      "value": 0.89990000,
      "valueSat": 89990000,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 a01adb3a7258c9e95bc4d2f755ad36e8f652cfc5 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914a01adb3a7258c9e95bc4d2f755ad36e8f652cfc588ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "yav18uegWthEs6JgABm94PDsgLkYW3CDnK"
        ]
      }
    }
  ],
  "blockhash": "00000c3afa8e8f3095e9894f524e704b435349cf43d479018308cd8145b087ea",
  "height": 209034,
  "confirmations": 3,
  "time": 1573545089,
  "blocktime": 1573545089,
  "instantlock": true,
  "instantlock_internal": false,
  "chainlock": true
}
[root@blockchain-node2 rpc_shell]# 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值