Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
liangjh01 opened this issue May 20, 2018 · 13 comments
Open

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

liangjh01 opened this issue May 20, 2018 · 13 comments

Comments

@liangjh01
Copy link

nebPay.call return a serielNumber,

@yupnano
Copy link
Contributor

yupnano commented May 20, 2018

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"
}

@roc198
Copy link

roc198 commented May 25, 2018

这个查询就没有成功过

@yupnano
Copy link
Contributor

yupnano commented May 26, 2018

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

@yupnano
Copy link
Contributor

yupnano commented May 26, 2018

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

@roc198
Copy link

roc198 commented May 26, 2018 via email

@yupnano
Copy link
Contributor

yupnano commented May 26, 2018

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

@harryge00
Copy link

harryge00 commented May 30, 2018

@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

@yupnano
Copy link
Contributor

yupnano commented May 30, 2018

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]}"
}
}

@harryge00
Copy link

@yupnano Thanks. When will they be updated?

@yupnano
Copy link
Contributor

yupnano commented May 31, 2018

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

@harryge00
Copy link

harryge00 commented Jun 1, 2018

@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
Copy link

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

@yupnano
Copy link
Contributor

yupnano commented Jun 2, 2018

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants