tx_getTransactionReceipt
根据交易哈希返回交易回执信息。
Parameters
<string>
- 32字节的十六进制字符串,交易的哈希值。
Returns
<Receipt>
- Receipt对象字段如下:
version
:<string>
- 平台版本号。txHash
:<string>
- 交易哈希。vmType
:<string>
- 该笔交易执行引擎类型,EVM
或JVM
。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:交易未被确认
- # Request
- curl localhost:8081 --data '{"jsonrpc":"2.0", "namespace":"global", "method":"tx_getTransactionReceipt","params":["0x0e0758305cde33c53f8c2b852e75bc9b670c14c547dd785d93cb48f661a2b36a "],"id":1}'
- # Response
- {
- "jsonrpc": "2.0",
- "namespace":"global",
- "id": 1,
- "code": -32001,
- "message": "Not found receipt by 0x0e0758305cde33c53f8c2b852e75bc9b670c14c547dd785d93cb48f661a2b36a"
- }
Example2:合约部署出错
在这个例子中我们使用以下合约来重现这个情况:
- contract TestContractor{
- int length = 0;
- modifier justForTest(){
- length = 2;
- throw;
- _;
- }
- function TestContractor()justForTest{
- }
- function getLength() returns(int){
- return length;
- }
- }
我们将该合约编译后返回的bin作为contract_deployContract方法中参数payload
的值,那么部署合约请求如下:
- # Request
- curl localhost:8081 --data '{"jsonrpc":"2.0", "namespace":"global", "method":"contract_deployContract", "params":[{
- "from":"17d806c92fa941b4b7a8ffffc58fa2f297a3bffc",
- "nonce":7021040367249265,
- "payload":"0x60606040526000600055346000575b60026000556000565b5b5b603f806100266000396000f3606060405260e060020a6000350463be1c766b8114601c575b6000565b3460005760266038565b60408051918252519081900360200190f35b6000545b9056",
- "timestamp":1487042279126000000,
- "signature":"0xfc1cb1986dd4ee4a5f8d8238e2f7bac1866aad235d587eb641d76270bf686418310ab7d42dc0f2575aa858a88ae7732cd617281eedb38636e843ff3b49b8f8ab01"}],"id":1}'
- # Response
- {
- "jsonrpc": "2.0",
- "namespace":"global",
- "id": 1,
- "code": 0,
- "message": "SUCCESS",
- "result": "0x33aef7e6bad2ae27c23a8ab44f56aef87042f1f0b02e1b0ee5e8a304705292a6"
- }
接着,根据返回的hash查找这条记录的receipt,会发现返回了合约部署失败的error:
- # Request
- curl localhost:8081 --data '{"jsonrpc":"2.0", "namespace":"global", "method":"tx_getTransactionReceipt","params":["0x33aef7e6bad2ae27c23a8ab44f56aef87042f1f0b02e1b0ee5e8a304705292a6"],"id":1}'
- # Response
- {
- "jsonrpc":"2.0",
- "namespace":"global",
- "id":1,
- "code":-32004,
- "message":"DEPLOY_CONTRACT_FAILED"
- }
Example3:合约方法调用出错
在这个例子中我们使用以下合约来重现这个情况:
- contract TestContractor{
- int length = 0;
- modifier justForTest(){
- length = 2;
- throw;
- _;
- }
- function TestContractor(){
- }
- function getLength()justForTest returns(int){
- return length;
- }
- }
调用合约getLength()
方法的请求如下:
- # Request
- curl localhost:8081 --data '{"jsonrpc":"2.0", "namespace":"global", "method": "contract_invokeContract", "params": [{
- "from": "17d806c92fa941b4b7a8ffffc58fa2f297a3bffc",
- "to":"0xaeccd2fd1118334402c5de1cb014a9c192c498df",
- "timestamp":1487042517534000000,
- "nonce":2472630987523856,
- "payload":"0xbe1c766b",
- "signature":"0x8c56f025610dd9cb3f4ac346d35978639a536505527b7593d87f3b45c35328637280995ed32f6a6809069da915740b363c1b357cf31a7eb83e05dde0afc4937300"}],"id": 1}'
- # Response
- {
- "jsonrpc": "2.0",
- "namespace":"global",
- "id": 1,
- "code": 0,
- "message": "SUCCESS",
- "result":"0x5233d18f46e9c1ed49dbdeb4273c1c1e0eb176efcedf6edb6d9fa59d33d02fee "
- }
接着,根据返回的hash查找这条记录的receipt,会发现返回了方法调用失败的error:
- # Request
- curl localhost:8081 --data '{"jsonrpc":"2.0", "namespace":"global", "method":"tx_getTransactionReceipt","params":["0x5233d18f46e9c1ed49dbdeb4273c1c1e0eb176efcedf6edb6d9fa59d33d02fee"],"id":1}'
- # Response
- {
- "jsonrpc":"2.0",
- "namespace":"global",
- "id":1,
- "code":-32005,
- "message":"INVOKE_CONTRACT_FAILED"
- }
Example4:签名非法
我们将Example3合约方法调用失败例子的参数稍微修改一下,把from
的最后一个字母“c”改为“0”,那么调用合约请求如下:
- # Request
- curl localhost:8081 --data '{"jsonrpc":"2.0", "namespace":"global", "method": "contract_invokeContract", "params": [{
- "from": "17d806c92fa941b4b7a8ffffc58fa2f297a3bff0",
- "to":"0xaeccd2fd1118334402c5de1cb014a9c192c498df",
- "timestamp":1481872888621000000,
- "nonce":9206467481004664,
- "payload":"0xbe1c766b",
- "signature":"0x57dfa7f2c2d8c762c9c0e5ef7b1c4dda84b584f36799ab751891c8dc553862145f64d1991441c9460481af4e4231db393744ad3cfd37c8cce74c873002745aa401"}],"id": 1}'
- # Response
- {
- "jsonrpc": "2.0",
- "namespace":"global",
- "id": 1,
- "code": 0,
- "id": "SUCCESS",
- "result":"0x621d09cd9d5e9027d9b82c5e1fd911ac31297775dbb0c4dab6c6fcd64310fe23"
- }
接着,根据返回的hash查找这条记录的receipt,会发现返回了签名非法的error:
- # Request
- curl localhost:8081 --data '{"jsonrpc":"2.0", "namespace":"global", "method":"tx_getTransactionReceipt","params":["0x621d09cd9d5e9027d9b82c5e1fd911ac31297775dbb0c4dab6c6fcd64310fe23"],"id":1}'
- # Response
- {
- "jsonrpc": "2.0",
- "namespace":"global",
- "id": 1,
- "code": -32003,
- "message": " SIGFAILED "
- }
Example5
- # Request
- curl -X POST --data '{"jsonrpc": "2.0", "namespace":"global", "method": "tx_getTransactionReceipt", "params":["0x70376053e11bc753b8cc778e2fbb662718671712e1744980ba1110dd1118c059"], "id": 1}'
- # Response
- {
- "jsonrpc": "2.0",
- "namespace": "global",
- "id": 1,
- "code": 0,
- "message": "SUCCESS",
- "result": {
- "version": "1.3",
- "txHash": "0x70376053e11bc753b8cc778e2fbb662718671712e1744980ba1110dd1118c059",
- "vmType": "EVM",
- "contractAddress": "0x0000000000000000000000000000000000000000",
- "ret": "0x0",
- "log": [
- {
- "address": "0xaeccd2fd1118334402c5de1cb014a9c192c498df",
- "topics": [
- "0x24abdb5865df5079dcc5ac590ff6f01d5c16edbc5fab4e195d9febd1114503da"
- ],
- "data": "0000000000000000000000000000000000000000000000000000000000000064",
- "blockNumber": 2,
- "blockHash": "0x0c14a89b9611f7f268f26d4ce552de966bebba4aab6aaea988022f3b6817f61b",
- "txHash": "0x70376053e11bc753b8cc778e2fbb662718671712e1744980ba1110dd1118c059",
- "txIndex": 0,
- "index": 0
- }
- ]
- }
- }
当前内容版权归 Hyperchain 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 Hyperchain .