tx_getTransactionReceipt

根据交易哈希返回交易回执信息。

Parameters

  1. <string> - 32字节的十六进制字符串,交易的哈希值。

Returns

  1. <Receipt> - Receipt对象字段如下:
  • version: <string> - 平台版本号。
  • txHash: <string> - 交易哈希。
  • vmType: <string> - 该笔交易执行引擎类型,EVMJVM
  • contractAddress: <string> - 合约地址。
  • gasUsed: <number> - 该笔交易所耗费的gas。
  • ret: <string> - 合约编译后的字节码或合约执行的结果。
  • log: [<Log>] - Log对象数组,表示合约中的event log信息。Log对象如下:
    • address: <string> - 产生事件日志的合约地址。
    • topics: [<string>] - 一系列的topic,第一个topic是event的唯一标识。
    • data: <string> - 日志信息。
    • blockNumber: <number> - 所属区块的区块号。
    • blockHash: <string> - 所属区块的区块哈希。
    • txHash: <string> - 所属交易的交易哈希。
    • txIndex: <number> - 所属交易在当前区块交易列表中的偏移量。
    • index: <number> - 该日志在本条交易产生的所有日志中的偏移量。

如果该笔交易还没被确认,则返回的错误码为-32001的error,如果该笔交易处理过程中发生错误,则错误可能是:

  • OUTOFBALANCE - 余额不足,对应code是-32002;
  • SIGFAILED - 签名非法,对应code是-32003;
  • DEPLOY_CONTRACT_FAILED - 合约部署失败,对应code是-32004;
  • INVOKE_CONTRACT_FAILED - 合约方法调用失败,对应code是-32005;
  • INVALID_PERMISSION - 合约操作权限不够,对应code是-32008;

Example1:交易未被确认

  1. # Request
  2. curl localhost:8081 --data '{"jsonrpc":"2.0", "namespace":"global", "method":"tx_getTransactionReceipt","params":["0x0e0758305cde33c53f8c2b852e75bc9b670c14c547dd785d93cb48f661a2b36a "],"id":1}'
  3.  
  4. # Response
  5. {
  6. "jsonrpc": "2.0",
  7. "namespace":"global",
  8. "id": 1,
  9. "code": -32001,
  10. "message": "Not found receipt by 0x0e0758305cde33c53f8c2b852e75bc9b670c14c547dd785d93cb48f661a2b36a"
  11. }

Example2:合约部署出错

在这个例子中我们使用以下合约来重现这个情况:

  1. contract TestContractor{
  2. int length = 0;
  3.  
  4. modifier justForTest(){
  5. length = 2;
  6. throw;
  7. _;
  8. }
  9. function TestContractor()justForTest{
  10. }
  11.  
  12. function getLength() returns(int){
  13. return length;
  14. }
  15. }

我们将该合约编译后返回的bin作为contract_deployContract方法中参数payload的值,那么部署合约请求如下:

  1. # Request
  2. curl localhost:8081 --data '{"jsonrpc":"2.0", "namespace":"global", "method":"contract_deployContract", "params":[{
  3. "from":"17d806c92fa941b4b7a8ffffc58fa2f297a3bffc",
  4. "nonce":7021040367249265,
  5. "payload":"0x60606040526000600055346000575b60026000556000565b5b5b603f806100266000396000f3606060405260e060020a6000350463be1c766b8114601c575b6000565b3460005760266038565b60408051918252519081900360200190f35b6000545b9056",
  6. "timestamp":1487042279126000000,
  7. "signature":"0xfc1cb1986dd4ee4a5f8d8238e2f7bac1866aad235d587eb641d76270bf686418310ab7d42dc0f2575aa858a88ae7732cd617281eedb38636e843ff3b49b8f8ab01"}],"id":1}'
  8.  
  9. # Response
  10. {
  11. "jsonrpc": "2.0",
  12. "namespace":"global",
  13. "id": 1,
  14. "code": 0,
  15. "message": "SUCCESS",
  16. "result": "0x33aef7e6bad2ae27c23a8ab44f56aef87042f1f0b02e1b0ee5e8a304705292a6"
  17. }

接着,根据返回的hash查找这条记录的receipt,会发现返回了合约部署失败的error:

  1. # Request
  2. curl localhost:8081 --data '{"jsonrpc":"2.0", "namespace":"global", "method":"tx_getTransactionReceipt","params":["0x33aef7e6bad2ae27c23a8ab44f56aef87042f1f0b02e1b0ee5e8a304705292a6"],"id":1}'
  3.  
  4. # Response
  5. {
  6. "jsonrpc":"2.0",
  7. "namespace":"global",
  8. "id":1,
  9. "code":-32004,
  10. "message":"DEPLOY_CONTRACT_FAILED"
  11. }

Example3:合约方法调用出错

在这个例子中我们使用以下合约来重现这个情况:

  1. contract TestContractor{
  2. int length = 0;
  3.  
  4. modifier justForTest(){
  5. length = 2;
  6. throw;
  7. _;
  8. }
  9. function TestContractor(){
  10. }
  11.  
  12. function getLength()justForTest returns(int){
  13. return length;
  14. }
  15. }

调用合约getLength()方法的请求如下:

  1. # Request
  2. curl localhost:8081 --data '{"jsonrpc":"2.0", "namespace":"global", "method": "contract_invokeContract", "params": [{
  3. "from": "17d806c92fa941b4b7a8ffffc58fa2f297a3bffc",
  4. "to":"0xaeccd2fd1118334402c5de1cb014a9c192c498df",
  5. "timestamp":1487042517534000000,
  6. "nonce":2472630987523856,
  7. "payload":"0xbe1c766b",
  8. "signature":"0x8c56f025610dd9cb3f4ac346d35978639a536505527b7593d87f3b45c35328637280995ed32f6a6809069da915740b363c1b357cf31a7eb83e05dde0afc4937300"}],"id": 1}'
  9.  
  10. # Response
  11. {
  12. "jsonrpc": "2.0",
  13. "namespace":"global",
  14. "id": 1,
  15. "code": 0,
  16. "message": "SUCCESS",
  17. "result":"0x5233d18f46e9c1ed49dbdeb4273c1c1e0eb176efcedf6edb6d9fa59d33d02fee "
  18. }

接着,根据返回的hash查找这条记录的receipt,会发现返回了方法调用失败的error:

  1. # Request
  2. curl localhost:8081 --data '{"jsonrpc":"2.0", "namespace":"global", "method":"tx_getTransactionReceipt","params":["0x5233d18f46e9c1ed49dbdeb4273c1c1e0eb176efcedf6edb6d9fa59d33d02fee"],"id":1}'
  3.  
  4. # Response
  5. {
  6. "jsonrpc":"2.0",
  7. "namespace":"global",
  8. "id":1,
  9. "code":-32005,
  10. "message":"INVOKE_CONTRACT_FAILED"
  11. }

Example4:签名非法

我们将Example3合约方法调用失败例子的参数稍微修改一下,把from的最后一个字母“c”改为“0”,那么调用合约请求如下:

  1. # Request
  2. curl localhost:8081 --data '{"jsonrpc":"2.0", "namespace":"global", "method": "contract_invokeContract", "params": [{
  3. "from": "17d806c92fa941b4b7a8ffffc58fa2f297a3bff0",
  4. "to":"0xaeccd2fd1118334402c5de1cb014a9c192c498df",
  5. "timestamp":1481872888621000000,
  6. "nonce":9206467481004664,
  7. "payload":"0xbe1c766b",
  8. "signature":"0x57dfa7f2c2d8c762c9c0e5ef7b1c4dda84b584f36799ab751891c8dc553862145f64d1991441c9460481af4e4231db393744ad3cfd37c8cce74c873002745aa401"}],"id": 1}'
  9.  
  10. # Response
  11. {
  12. "jsonrpc": "2.0",
  13. "namespace":"global",
  14. "id": 1,
  15. "code": 0,
  16. "id": "SUCCESS",
  17. "result":"0x621d09cd9d5e9027d9b82c5e1fd911ac31297775dbb0c4dab6c6fcd64310fe23"
  18. }

接着,根据返回的hash查找这条记录的receipt,会发现返回了签名非法的error:

  1. # Request
  2. curl localhost:8081 --data '{"jsonrpc":"2.0", "namespace":"global", "method":"tx_getTransactionReceipt","params":["0x621d09cd9d5e9027d9b82c5e1fd911ac31297775dbb0c4dab6c6fcd64310fe23"],"id":1}'
  3.  
  4. # Response
  5. {
  6. "jsonrpc": "2.0",
  7. "namespace":"global",
  8. "id": 1,
  9. "code": -32003,
  10. "message": " SIGFAILED "
  11. }

Example5

  1. # Request
  2. curl -X POST --data '{"jsonrpc": "2.0", "namespace":"global", "method": "tx_getTransactionReceipt", "params":["0x70376053e11bc753b8cc778e2fbb662718671712e1744980ba1110dd1118c059"], "id": 1}'
  3.  
  4. # Response
  5. {
  6. "jsonrpc": "2.0",
  7. "namespace": "global",
  8. "id": 1,
  9. "code": 0,
  10. "message": "SUCCESS",
  11. "result": {
  12. "version": "1.3",
  13. "txHash": "0x70376053e11bc753b8cc778e2fbb662718671712e1744980ba1110dd1118c059",
  14. "vmType": "EVM",
  15. "contractAddress": "0x0000000000000000000000000000000000000000",
  16. "ret": "0x0",
  17. "log": [
  18. {
  19. "address": "0xaeccd2fd1118334402c5de1cb014a9c192c498df",
  20. "topics": [
  21. "0x24abdb5865df5079dcc5ac590ff6f01d5c16edbc5fab4e195d9febd1114503da"
  22. ],
  23. "data": "0000000000000000000000000000000000000000000000000000000000000064",
  24. "blockNumber": 2,
  25. "blockHash": "0x0c14a89b9611f7f268f26d4ce552de966bebba4aab6aaea988022f3b6817f61b",
  26. "txHash": "0x70376053e11bc753b8cc778e2fbb662718671712e1744980ba1110dd1118c059",
  27. "txIndex": 0,
  28. "index": 0
  29. }
  30. ]
  31. }
  32. }