我不会从一个简单的函数中获得任何返回数据,当部署在Sopolia testnet上时,它在VM中可以正常工作。
编译器: 0.8.7;
rpc:https://rpc-sepolia.rockx.com
function gerReferalCode() external returns ( uint256 ) {
uint256 h;
do {
h = _hash(1);
} while ( referalIsUsed[ h ] );
referalIsUsed[ h ] = true;
referalCode[ msg.sender ] = h;
Data storage d = signings[ h ];
d.owner = msg.sender;
return h;
}在混合中使用相同的合同:
混音VM (伦敦)
input 0x8df...8c783
decoded input {}
decoded output {
"0": "uint256: 3544079616"
}
logs []注射提供者( Sepolia ):
input 0x8df...8c783
decoded output -
val 0 weiWeb3代码响应:
blockHash
:
"0x29810da2e36a8ec29db6e3cc50557c0ac3146283acf9231527a295dec6b0b9aa"
blockNumber
:
2312093
contractAddress
:
null
cumulativeGasUsed
:
75924
effectiveGasPrice
:
2500000007
events
:
{}
from
:
"0xbb4896575291881a7bbc0f945ec3bcd402a44794"
gasUsed
:
75924
logsBloom
:
"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
status
:
true
to
:
"0xbc2bacef89a144acf941d2b24bfe674ede6d832e"
transactionHash
:
"0x126f380273d8911611d2190bc67c53097d6ee012ed32f349a49786d323f7063b"
transactionIndex
:
0
type
:
"0x2"发布于 2022-11-18 09:36:13
从可能改变块链状态的函数中获取返回的数据是不可能的。这是稳固性的局限性之一。这就是为什么函数要返回完整的块信息。
如果要获取数据,则需要将函数更改为视图函数,而不是更改块链中的状态。
https://ethereum.stackexchange.com/questions/139606
复制相似问题