nebPay.js icon indicating copy to clipboard operation
nebPay.js copied to clipboard

How can I get the return value from contract function call?

Open liangjh01 opened this issue 6 years ago • 13 comments

nebPay.call return a serielNumber,

liangjh01 avatar May 20 '18 02:05 liangjh01

you should use queryPayInfo(serielNumber) to query the transaction result, then you can get the result value of the function. The queried transaction result is shown below, and the "execute_result" is the return value.

{
    "code": 0,
    "data": {
        "data": "eyJGdW5jdGlvbiI6InNhdmUiLCJBcmdzIjoiW1wibmVidWxhc1wiLFwibmFzXCJdIn0=",
        "contractAddress": "",
        "type": "call",
        "nonce": 66,
        "gasLimit": "200000",
        "gasUsed": "",
        "chainId": 1,
        "from": "n1GDCCpQ2Z97o9vei2ajq6frrTPyLNCbnt7",
        "to": "n1udJnsraDnmL2c5qdG5DCba2eMpA4dskfU",
        "value": "0",
        "hash": "b07aba7cbef18ac9f99a6ff9ae6b381ece5a241781f6ec88b6219eec39f47b54",
        "gasPrice": "1000000",
        "status": 2,
        "timestamp": 1526720015,
        "execute_error": "",
        "execute_result": ""
    },
    "msg": "success"
}

yupnano avatar May 20 '18 14:05 yupnano

这个查询就没有成功过

roc198 avatar May 25 '18 11:05 roc198

你好,交易是在主网还是测试网?用callback指定查询网络了吗?

yupnano avatar May 26 '18 01:05 yupnano

@roc198 可以贴一下已经成功的那条交易对应的serialNumber吗? 我来查一下试试

yupnano avatar May 26 '18 04:05 yupnano

主网测试网都试了,我自己写的查不出来,就用你们的超级辞典试了一下,也是不行,nebPay已经更新到github上最新版本,指定callback也是如此, CWTqxCy9h3nFZoDYh5gpICRp2YEf0zrh这个是成功的交易号,执行结果

txhash:621403db64f148be0eff31ed58b57ef7ad6e8fb3150cee2326a35ded5e1d75c0

浏览器日志信息:

在 2018年5月26日,09:40,yupnano [email protected] 写道:

你好,交易是在主网还是测试网?用callback指定查询网络了吗?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/nebulasio/nebPay/issues/26#issuecomment-392226332, or mute the thread https://github.com/notifications/unsubscribe-auth/AATx_9SwqG0wNsZwSdkV_b324eHTwQnBks5t2LKLgaJpZM4UF7Xn.

roc198 avatar May 26 '18 10:05 roc198

这条序列号在主网he测试网都查不到,看来是没有发到查询服务器上,很可能是浏览器插件没有上传,你可以更新一下插件试试。

yupnano avatar May 26 '18 14:05 yupnano

@yupnano I have use queryPayInfo, I got

{
    "code":0,
    "data":{
        "data":"eyJGdW5jdGlvbiI6InNwaW4iLCJBcmdzIjoiW10ifQ==",
        "contractAddress":"",
        "type":"call",
        "nonce":30,
        "gasLimit":"200000",
        "gasUsed":"",
        "chainId":1001,
        "from":"n1GHASp6Pku4D35hvgGipS3Pjt2iX7uYhBZ",
        "to":"n21XtnUtaLaPi17ssnjpnjT34CXwE79Z8pb",
        "value":"1000000000000000",
        "hash":"840804a2b75940920b84a0fa8bbf577b97dad40601291faf2bdf7fc19e6af2f6",
        "gasPrice":"1000000",
        "status":2,
        "timestamp":1527693239
    },
    "msg":"success"
}

But no execute_result is returned. It is testnet and serialnumber is r3hcKpzsJW4SgVGdrXLSKuFPaamzoXii

harryge00 avatar May 30 '18 15:05 harryge00

please try neb.js with api getTransactionReceipt, the explorer and queryPayInfo has not updated yet.

{ "result": { "hash": "840804a2b75940920b84a0fa8bbf577b97dad40601291faf2bdf7fc19e6af2f6", "chainId": 1001, "from": "n1GHASp6Pku4D35hvgGipS3Pjt2iX7uYhBZ", "to": "n21XtnUtaLaPi17ssnjpnjT34CXwE79Z8pb", "value": "1000000000000000", "nonce": "30", "timestamp": "1527693239", "type": "call", "data": "eyJGdW5jdGlvbiI6InNwaW4iLCJBcmdzIjoiW10ifQ==", "gas_price": "1000000", "gas_limit": "200000", "contract_address": "", "status": 1, "gas_used": "20356", "execute_error": "", "execute_result": "{"fromValue":"1000000000000000","prize":0,"slots":[1,4,0]}" } }

yupnano avatar May 30 '18 15:05 yupnano

@yupnano Thanks. When will they be updated?

harryge00 avatar May 30 '18 15:05 harryge00

@harryge00 It's now updated, please try it again.

yupnano avatar May 31 '18 06:05 yupnano

@yupnano

Both execute_result and execute_error is ""

{
    "code":0,
    "data":{
        "execute_error":"",
        "gas_price":"1000000",
        "data":"eyJGdW5jdGlvbiI6InNwaW4iLCJBcmdzIjoiW10ifQ==",
        "gas_used":"",
        "contract_address":"",
        "type":"call",
        "nonce":34,
        "gas_limit":"200000",
        "chainId":1001,
        "from":"n1GHASp6Pku4D35hvgGipS3Pjt2iX7uYhBZ",
        "to":"n21msTLFKy9uFdnvTQAwUZJjg6VdwKJM4Qz",
        "execute_result":"",
        "value":"1000000000000000",
        "hash":"40f3d1210cc5ac3bdf9c9ddbff11d4e075a5de6f9f2eea57f355c7d192b71f1b",
        "status":2,
        "timestamp":1527864641
    },
    "msg":"success"
}

harryge00 avatar Jun 01 '18 14:06 harryge00

@yupnano It seems like the transaction has not completed when I queryPayInfo, just retried and got the correct result. Thanks.

harryge00 avatar Jun 01 '18 14:06 harryge00

@harryge00 You are right, the transaction has not been packed onto chain, and it was pending. You need to check the "status":1 to make sure the transaction is successful.

The status code is as follows:

  • 0: Failed. It means the transaction has been submitted on chain but its execution failed.
  • 1: Successful. It means the transaction has been submitted on chain and its execution successeed.
  • 2: Pending. It means the transaction hasn't been packed into a block.

yupnano avatar Jun 02 '18 07:06 yupnano