gpt4 book ai didi

javascript - 为什么我们不能从运行在智能合约上的 sendTransaction() 获得返回值?

转载 作者:行者123 更新时间:2023-12-05 00:38:44 25 4
gpt4 key购买 nike

所有关于此的讨论都提到不可能从 sendTransaction() 获得返回值,该函数运行在合约状态正在更改的合约函数上。我不明白为什么返回的值不能记录在区 block 链上的事务日志中,类似于事件,因此可以在事务确认时检索它:

web3.eth.sendTransaction(...)
.on('confirmation', function(1, receipt){ ... // retrieving value returned by smart contract function here })

最佳答案

日志用于描述从合约发出的事件——这是从交易中获取数据的当前解决方案——,因此返回数据不能进入那里。
然而,在收据中包含一个 return_data 已经被讨论过并且显然被遗忘了。 EIP758 , 有 following sollution :

EIP 658 originally proposed adding return data to transaction receipts. However, return data is not charged for (as it is not stored on the blockchain), so adding it to transaction receipts could result in DoS and spam opportunities. Instead, a simple Boolean status field was added to transaction receipts. This modified version of EIP 658 was included in the Byzantium hard fork. While the status field is useful, applications often need the return data as well.


The primary advantage of using the strategy outlined here is efficiency: no extra data needs to be stored on the blockchain, and minimal extra computational load is imposed on nodes. Since light clients have the current state, they can compute and send return data notifications without contacting a server. Although after-the-fact lookups of the return value would not be supported, this is consistent with the conventional use of return data, which are only accessible to the caller when the function returns, and are not stored for later use.


还有这个 go client pull request ,它没有通过,因为最好的解决方案是以太坊硬 fork ——尽管从那时起我们就有了一些,但它没有发生。

关于javascript - 为什么我们不能从运行在智能合约上的 sendTransaction() 获得返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72429607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com