是否有任何方法使用web3py来理解事务是否生成错误?我有下面的代码,我想知道令牌是否已经被铸造,以便返回API端点中的错误。
key = contract.functions.safeMint(tokenId, metadata_uri).buildTransaction({
'nonce': web3obj.eth.get_transaction_count(current_address),
'from': current_address,
'gas': 3000000,
'value': tokenPrice
})
try:
signed_tx = web3obj.eth.account.signTransaction(key, private_key=current_privkey)
txhash = web3obj.eth.sendRawTransaction(signed_tx.rawTransaction)
print("txhash:",txhash.hex())
except Exception as e:
print(e)发布于 2021-08-17 09:54:07
实际上,在使用estimateGas方法发送事务之前,您可以检测事务是否会失败。通常,这种方法应该返回在区块链上需要执行事务的gas值,如果事务将要失败,那么estimateGas还将在将事务发送到区块链之前返回一个错误。这将为任何与您的逻辑交互的人节省事务费用。
https://ethereum.stackexchange.com/questions/107273
复制相似问题