You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Solidity合约getFromStorage函数运行时回滚错误排查求助

Solidity合约getFromStorage函数调用回滚问题排查

我编写的Solidity合约其余部分运行正常,但getFromStorage函数调用时触发交易回滚,执行失败。相关代码和错误信息如下:

合约代码

address payable public coldStorage;
event toColdStorage (address from, uint256 amount, uint toBlockchain, string toAddress);
event removedFromColdStorage (address to, uint256 amount, uint fromBlockchain, string fromAddress);

function getFromStorage(address payable _to, uint _fromBlockchain, string memory _fromAddress) public payable {
    require(msg.sender == coldStorage, "Only the owners can call this function");
    _to.transfer(msg.value);
    emit removedFromColdStorage(_to, msg.value, _fromBlockchain, _fromAddress);
}

Python调用代码

contract.functions.getFromStorage(w3.eth.accounts[2], 2, '9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM').transact({'value':500000000000000000})

错误信息

raise ContractLogicError(f'execution reverted: {response["error"]["message"]}')
web3.exceptions.ContractLogicError: execution reverted: VM Exception while processing transaction: revert

排查关键点

  • 权限校验失败:函数第一行require(msg.sender == coldStorage)是最可能的触发回滚的原因。当前Python代码未指定transact的from字段,默认使用w3.eth.default_account作为交易发起者,需确认该账户是否与合约中coldStorage变量的实际值完全一致。
  • 账户余额不足:确认交易发起者(即coldStorage账户)的余额是否足够支付500000000000000000 wei(0.5 ETH),若余额不足,transfer操作会触发回滚。
  • 参数类型匹配:检查_fromBlockchain参数类型(合约中为uint,Python传入整数2无问题);_to参数为address payable,w3.eth.accounts[2]作为标准账户地址默认支持支付,此部分大概率无问题。

内容的提问来源于stack exchange,提问作者ymuhamma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 07:06:32