Should contract revert errors be thrown on waitForTransactionReceipt rather than writeContract #3890
0xCryptoMag
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I was experimenting with both functions and I was kind of surprised when my script was throwing
`
ContractFunctionExecutionError: The contract function "execute" reverted with the following reason:
User is not allowed to use this function
Contract Call:
address: 0x...................
`
when using the writeContract function when I expected that error to be thrown on the waitForTransactionReceipt. The docs for writeContract's Return Value has
So it seems the intent of writeContract is not evaluate the data and final stateof the transaction, but rather only to see if the transaction successfully broadcasted to the network. Which is why it only returns the hash because the hash is proof that it was successfully broadcasted.
I personally like the idea of writeContract returning only a hash and only throwing after calling waitForTransactionReceipt({hash}), for the following reason: let's say a hash is returned, but it takes 2 hours for the txn to be mined. After receiving the hash, writeContract resolves to a Hash, and in the meantime there is no thrown error on a contract reversion 2 hours later.
What do you guys think? Am I wrong in my understanding somewhere? Is there some sort of pre-broadcast / node gossip rejection that would explain this? In the meantime we can just use waitForTransactionReceipt and inspect the status attribute, this works perfectly fine as well.
Beta Was this translation helpful? Give feedback.
All reactions