我正在努力抓住要求()交易恢复时出错,但我得到了交易的哈希值,我正在使用web3.py
def addParticipants(request):
web3 = Web3(HTTPProvider(settings.Blockchain_IP_address, request_kwargs={'timeout': 60}))
project_address = '0x93aeD90401a182247EE28848229531bC78053cd6'
project = web3.eth.contract(address=project_address,
abi=Project_sol.abi,
bytecode=Project_sol.bytecode)
func_to_call = 'addParticipant'
addParticipant = project.functions[func_to_call]
result = addParticipant(settings.ADMIN_ACCOUNT,0).transact( {'from': settings.ADMIN_ACCOUNT, 'gasLimit': '6000000', 'gasPrice': '0', 'gas': 600000})
web3.eth.waitForTransactionReceipt(result)
print(result)
坚固性方法:
function addParticipant(address _Participant, uint _weight)public isOwner returns (bool) {
require(_weight!=0,"weight cannot be null");
require(status,"this Donation is closed");
Participants[_Participant].weight = _weight;
Participants[_Participant].status = true;
ParticipantsIndex[ParticipantsIndexSize] = _Participant;
ParticipantsIndexSize++;
emit ParticipantAction(_Participant, 'added');
return true;
}
该函数应该抛出错误说
“权重不能为空”
我按照此处找到的类似问题中的答案进行操作:Python 中的 Solidity“require”错误消息 https://stackoverflow.com/questions/72727267/solidity-require-error-message-in-python
您可以使用fetch_transaction_revert_reason https://web3-ethereum-defi.readthedocs.io/api/_autosummary/eth_defi.revert_reason.fetch_transaction_revert_reason.html#eth_defi.revert_reason.fetch_transaction_revert_reason的方法web3-以太坊-defi https://github.com/tradingstrategy-ai/web3-ethereum-defi。
您只需导入模块,如果由于 require() 错误而未执行事务,您可以使用以下命令:
fetch_transaction_revert_reason(web3, tx_hash)
这将创建一个包含文本“执行已恢复”的字符串,后跟 require 方法提供的错误消息。
在您的情况下,您可以在收据命令之前添加以下行:
fetch_transaction_revert_reason(web3, result)
这样应该会在您的控制台中打印:
执行恢复:权重不能为空
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)