Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Transactions 如何在发送以太网时检查合同调用的返回值?_Transactions_Return Value_Ethereum_Solidity_Ether - Fatal编程技术网

Transactions 如何在发送以太网时检查合同调用的返回值?

Transactions 如何在发送以太网时检查合同调用的返回值?,transactions,return-value,ethereum,solidity,ether,Transactions,Return Value,Ethereum,Solidity,Ether,调用这样的合同时: if(!contractname.somefunction()) throw; 它同时检查堆栈(检查契约调用是否失败)和契约调用是否成功但在内存中返回false 但是当使用.value()或.send()时,它只检查协定调用是否失败,这意味着它不会检查内存中的返回值 那么,如何在发送以太的同时检查内存中的返回值呢 ? 一个好方法是通过事件。对于somefunction(),您可以使用以下内容: contract Contractname { event ReturnV

调用这样的合同时:

if(!contractname.somefunction()) throw;
它同时检查堆栈(检查契约调用是否失败)和契约调用是否成功但在内存中返回false

但是当使用
.value()
.send()
时,它只检查协定调用是否失败,这意味着它不会检查内存中的返回值


那么,如何在发送以太的同时检查内存中的返回值呢 ?

一个好方法是通过事件。对于
somefunction()
,您可以使用以下内容:

contract Contractname {

  event ReturnValue(uint);

  function somefunction(){
    uint result;

    //...some computation right here

    emit ReturnValue(result);
  }

}

无法在同时返回返回值的同时发送乙醚。

 ! 无法从合同代码中检查事件,这是问题的关键…现在与我写的不同,
.transfer()
同时执行这两项操作。您使用的是哪个版本的solidity?@dushyanthkumarredy
0.4.x