链眼社区:专注于区块链安全,区块链数据分析, 区块链信息整合,区块链技术服务和区块链技术咨询。

Parity RPC API手册:Parity扩展API(一)
龙行天下
2021-11-24 21:05:48

parity_allTransactionHashes - 获取交易池交易哈希

使用parity_allTransactionHashes调用获取交易池/交易队列中的交易哈希清单。

调用参数

返回值

parity_allTransactionHashes调用返回一个数组,其成员表示节点交易池中 的交易哈希。

示例代码

请求:

~$ curl --data '{
  "method":"parity_allTransactionHashes",
  "params":[],
  "id":1,
  "jsonrpc":"2.0"
}' -H "Content-Type: application/json" -X POST localhost:8545

响应结果:

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": [
    "0x530683c1197f5b78a93d2ac07d41bd51913ddabd703b332b7024c0a8b45ab1ef",
    "0x385ad71ae858c3b229c30d4ac690f86396f8fd48b32bdba966306a9c95ab52ad",
    "0xdabc1f5156b2635f60c67d8cc27e9b07526f9239e9af821e80655766365dfa8d"
  ]
}

parity_allTransactions - 获取交易池交易

使用parity_allTransactions调用返回交易队列中的所有交易。

调用参数

返回值

parity_allTransactions调用返回一个数组,每个成员表示一个交易,结构如下:

  • hash:交易哈希,32字节长
  • nonce:发送账户之前的交易总数
  • blockHash:交易所在区块的哈希,当交易待定时值为null
  • blockNumber:交易所在区块的编号,当交易待定时值为null
  • transactionIndex:交易在区块中的索引位置,当交易待定时值为null
  • from:发送账户地址
  • to:接收账户地址,当交易为合约创建交易时为null
  • value:交易金额,单位:wei
  • gasPrice:发送方提供的gas价格,单位:wei
  • gas:发送方提供的gas用量
  • input:交易附加数据
  • creates:被创建合约的地址或null,可选
  • raw:裸交易数据
  • publicKey:签名账号的公钥
  • chainId:交易的链ID
  • standardV:签名的标准化V字段,0或1
  • v:签名的V字段
  • r:签名的R字段
  • s:签名的S字段
  • condition:交易提交条件,区块号或时间戳或null,可选

示例代码

请求:

~$ curl --data '{
  "method":"parity_allTransactions",
  "params":[],
  "id":1,
  "jsonrpc":"2.0"
}' -H "Content-Type: application/json" -X POST localhost:8545

响应:

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": [
    {
      "blockHash": null,
      "blockNumber": null,
      "chainId": null,
      "condition": null,
      "creates": null,
      "from": "0x5f3dffcf347944d3739b0805c934d86c8621997f",
      "gas": "0x493e0",
      "gasPrice": "0x12a05f200",
      "hash": "0x045301a128ffcb4662dd199d1176bdf4cc9f0628e10d6bf120edfb52e3e39a78",
      "input": "0x13f56f730...f3b4dc000",
      "nonce": "0x577",
      "publicKey": "0x3bb...9ce1b1",
      "r": "0x6fd2c7a5dbb8795038ca258196083b3eabe15a20e3020c3f45e88f2e447be410",
      "raw": "0xf88b8247d202...83eef3f8916bb818ce7",
      "s": "0x5993992c547d20234aabfc8c32a58d25784255fef500383eef3f8916bb818ce7",
      "standardV": "0x0",
      "to": "0xe8b2d01ffa0a15736b2370b6e5064f9702c891b6",
      "transactionIndex": null,
      "v": "0x1b",
      "value": "0x0"
    },
    { ... }, { ... }, ...
  ]
}

parity_call - 串行调用多个交易

parity_call调用按顺序依次执行多个eth_call调用。

调用参数

  • 要执行的交易对象序列

返回值

parity_call调用返回每个eth_call调用的结果的数组。

示例代码

请求:

~$ curl --data '{
  "method":"parity_call",
  "params":[
    [
      {
        "from":"0x407d73d8a49eeb85d32cf465507dd71d507100c1",
        "to":"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
        "value":"0x186a0"
      },
      {
        "from":"0x407d73d8a49eeb85d32cf465507dd71d507100c1",
        "to":"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
        "value":"0x186a0"
      }
    ]
  ],
  "id":1,
  "jsonrpc":"2.0"
}' -H "Content-Type: application/json" -X POST localhost:8545

响应结果:

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": [
    "0x",
    "0x"
  ]
}

parity_cidV0 - 计算内容ID

parity_cidV0计算protobuf编码字节的v0版本IPFS内容ID。

调用参数

  • 要编码的数据

返回值

parity_cidV0调用返回base58编码的CID

示例代码

请求:

~$ curl --data '{
  "method":"parity_cidV0",
  "params":["0x666f6f626172"],
  "id":1,
  "jsonrpc":"2.0"
}' -H "Content-Type: application/json" -X POST localhost:8545

响应结果:

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": "QmSbFjqjd6nFwNHqsBCC7SK8GShGcayLUEtysJjNGhZAnC"
}

parity_composeTransaction - 补全交易字段

parity_composeTransaction调用可以补全不完整的交易对象, 结果可以接下来用于签名。

调用参数

  • from:发送账户地址
  • to:目标账户地址,可选
  • gas:交易gas用量,可选
  • gasPrice:承诺的gas价格,可选
  • value:交易金额,可选
  • data:交易附加数据或合约调用的ABI编码数据,可选
  • nonce:交易nonce值,可选
  • condition:提交交易的条件对象,可选,可以是整数区块号例如{block:1}或者 UTC时间戳(单位:秒)例如{time:1491290692}或者null。

返回值

parity_composeTransaction调用返回补全后的交易对象,可选字段以默认值填充。

示例代码

请求:

~$ curl --data '{
  "method":"parity_composeTransaction",
  "params":[
    {
      "from":"0xb60e8dd61c5d32be8058bb8eb970870f07233155",
      "to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567",
      "value":"0x9184e72a"
    }
  ],
  "id":1,
  "jsonrpc":"2.0"
}' -H "Content-Type: application/json" -X POST localhost:8545

响应结果:

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
    "condition": null,
    "data": "0x",
    "from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
    "gas": "0xe57e0",
    "gasPrice": "0x4a817c800",
    "nonce": "0x0",
    "to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
    "value": "0x9184e72a"
  }
}

parity_consensusCapability - 查询共识能力

parity_consensusCapability调用返回当前的共识算法能力。

调用参数

返回结果

parity_consensusCapability调用返回一个对象或字符串,例如: "capable", {"capableUntil":N}, {"incapableSince":N} 或 "unknown" (N 表示区块号).

示例代码

请求:

~$ curl --data '{
  "method":"parity_consensusCapability",
  "params":[],
  "id":1,
  "jsonrpc":"2.0"
}' -H "Content-Type: application/json" -X POST localhost:8545

响应结果:

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": "capable"
}

parity_decryptMessage - 解密消息

parity_decryptMessage调用使用一个ECIES公钥解密消息。

调用参数

  • 可以解密消息的账户
  • 加密的消息

返回值

parity_decryptMessage调用返回解密后的消息。

示例代码

请求:

~$ curl --data '{
  "method":"parity_decryptMessage",
  "params":[
    "0x00a329c0648769a73afac7f9381e08fb43dbea72",
    "0x0405afee7fa2ab3e48c27b00d543389270cb7267fc191ca1311f297255a83cbe8d77a4ba135b51560700a582924fa86d2b19029fcb50d2b68d60a7df1ba81df317a19c8def117f2b9cf8c2618be0e3f146a5272fb9e5528719d2d7a1bd91fa620901cffa756305c79c093e7af30fa3c1587029421351c34a7c1e5a2b"
  ],
  "id":1,
  "jsonrpc":"2.0"
}' -H "Content-Type: application/json" -X POST localhost:8545

响应结果:

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": "0x68656c6c6f20776f726c64" // hello world
}

parity_encryptMessage - 加密消息

parity_encryptMessage调用使用公钥加密指定数据。

调用参数

  • 使用secp256k1曲线生成的EC公钥,截取最后64字节
  • 要加密的消息

返回值

parity_encryptMessage调用返回加密的消息。

示例代码

请求:

~$ curl --data '{
  "method":"parity_encryptMessage",
  "params":[
    "0xD219959D466D666060284733A80DDF025529FEAA8337169540B3267B8763652A13D878C40830DD0952639A65986DBEC611CF2171A03CFDC37F5A40537068AA4F",
    "0x68656c6c6f20776f726c64"
  ],
  "id":1,
  "jsonrpc":"2.0"
}' -H "Content-Type: application/json" -X POST localhost:8545

响应结果:

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": "0x0491debeec5e874a453f84114c084c810708ebcb553b02f1b8c05511fa4d1a25fa38eb49a32c815e2b39b7bcd56d66648bf401067f15413dae683084ca7b01e21df89be9ec4bc6c762a657dbd3ba1540f557e366681b53629bb2c02e1443b5c0adc6b68f3442c879456d6a21ec9ed07847fa3c3ecb73ec7ee9f8e32d"
}

parity_getBlockHeaderByNumber - 查询区块头

使用parity_getBlockHeaderByNumber调用获取区块头,与eth_getBlockByNumber 的区别在于它不返回叔伯和交易数据。

调用参数

  • 要查询的区块号,或者字符串 'earliest', 'latest' 或 'pending'。

返回值

parity_getBlockHeaderByNumber调用返回区块头对象。

示例代码

请求:

~$ curl --data '{
  "method":"parity_getBlockHeaderByNumber",
  "params":["0x1b4"],
  "id":1,
  "jsonrpc":"2.0"
}' -H "Content-Type: application/json" -X POST localhost:8545

响应结果:

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
    "author": "0xbb7b8287f3f0a933474a79eae42cbca977791171",
    "difficulty": "0x4ea3f27bc",
    "extraData": "0x476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32",
    "gasLimit": "0x1388",
    "gasUsed": "0x0",
    "hash": "0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae",
    "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    "miner": "0xbb7b8287f3f0a933474a79eae42cbca977791171",
    "mixHash": "0x4fffe9ae21f1c9e15207b1f472d5bbdd68c9595d461666602f2be20daf5e7843",
    "nonce": "0x689056015818adbe",
    "number": "0x1b4",
    "parentHash": "0xe99e022112df268087ea7eafaf4790497fd21dbeeb6bd7a1721df161a6657a54",
    "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
    "sealFields": [
      "0xa04fffe9ae21f1c9e15207b1f472d5bbdd68c9595d461666602f2be20daf5e7843",
      "0x88689056015818adbe"
    ],
    "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
    "size": "0x21b",
    "stateRoot": "0xddc8b0234c2e0cad087c8b389aa7ef01f7d79b2570bccb77ce48648aa61c904d",
    "timestamp": "0x55ba467c",
    "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
  }
}

parity_getBlockReceipts - 获取区块全部交易收据

使用parity_getBlockReceipts调用获取指定区块的所有交易的收据, 这会比逐个查询交易收据更高效。

调用参数

  • 要查询的区块号,或者字符串'earliest', 'latest' 或 'pending'

返回值

parity_getBlockReceipts调用返回指定区块的所有交易的收据数组。

示例代码

请求:

~$ curl --data '{
  "method":"parity_getBlockReceipts",
  "params":["0x8D2B29"],
  "id":1,
  "jsonrpc":"2.0"
}' -H "Content-Type: application/json" -X POST localhost:8545

响应结果:

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": [
    {
      "blockHash": "0x64d67cf84d95f8dfa1e1c3b5a5260aaf801ac99529b4ec3ae19bb06ba78c7bd5",
      "blockNumber": "0x8d2b29",
      "contractAddress": null,
      "cumulativeGasUsed": "0x5208",
      "from": "0x4d6bb4ed029b33cf25d0810b029bd8b1a6bcab7b",
      "gasUsed": "0x5208",
      "logs": [],
      "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
      "root": null,
      "status": "0x1",
      "to": "0xe9c245293dac615c11a5bf26fcec91c3617645e4",
      "transactionHash": "0x1eba82fb5e8426b520c49a5d8dc6c24157e8f45fb9102aca4a99f5617c1539fc",
      "transactionIndex": "0x0"
    },
    {
      "blockHash": "0x64d67cf84d95f8dfa1e1c3b5a5260aaf801ac99529b4ec3ae19bb06ba78c7bd5",
      "blockNumber": "0x8d2b29",
      "contractAddress": null,
      "cumulativeGasUsed": "0x3fc28",
      "from": "0x0caf0d921b2bd24ca04e1f06344e976af223783b",
      "gasUsed": "0x3aa20",
      "logs": [],
      "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
      "root": null,
      "status": "0x1",
      "to": "0xf2bb17cb59746cae43d65eec233925b6584cddef",
      "transactionHash": "0x70a50d28db69e5c7a8686141f282530d52e7e3c625296dc53eb5684afa727886",
      "transactionIndex": "0x1"
    }
  ]
}

parity_hardwarePinMatrixAck - 解锁硬件钱包

使用parity_hardwarePinMatrixAck调用向硬件钱包发送一个pin来解锁。

调用参数

  • 要解锁的设备路径
  • 从pin matrix接收到的pin

返回值

parity_hardwarePinMatrixAck调用返回一个布尔值,表示是否成功解锁 设备。

示例代码

请求:

~$ curl --data '{
  "method":"parity_hardwarePinMatrixAck",
  "params":["USB_2b24_0001_14100000","1234"],
  "id":1,
  "jsonrpc":"2.0"
}' -H "Content-Type: application/json" -X POST localhost:8545

响应结果:

{ "id": 1, "jsonrpc": "2.0", "result": true } ```

合作伙伴