-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support solidity 0.8.4+ custom errors #323
Comments
Thanks for bringing this up. Just to clarify - would you prefer that the gem returns the full response instead of raising an error so that you can handle the error on your end? |
Throwing an error with all parsed data is better. I think current IOError is too basic. JS libs work this way. |
Ok got it. Can you take a look? I implemented custom solidity errors (if data is present), like the following:
You can do something like rescue Client::CustomSolidityError => e
pp JSON.parse(e.message.gsub("=>", ":"))
end |
This is good step forward, but the error could be parsed better. The custom solidity errors are parsed the same way as events. They have parameters and those parameters have solidity types. Here is how it is parsed using JS viem library:
Ideally, we should do the same. |
Ok, got it. I just read the documentation.
I'll spend some time thinking how this would be best implemented. We already have the logic now to raise a custom solidity error. Probably next step is to implement a |
Is there a specification on custom errors in ABI?
|
See, when I saw this library I was surprised on how contract functions are called: client.call(contract, "ownerOf", token_id) This is weird. As I would expect a function to be called on a contract because only the contract is aware of a function, but not the client. All js libraries I used do it this way. func = contract.function("safeTransferFrom", from, to, tokenId)
# eth_call to make sure the function doesn't revert
# experienced developers know that eth_estimateGas returns nonsense when function reverts
func.call()
# eth_estimateGas to make sure it is under the adequate limit
func.estimate_gas
tx = func.sign(key)
# eth_sendTransaction
client.eth_send_raw_transaction(tx.hex)
# store tx somewhere to ensure retries are possible
Tx.create!(hex: tx.hex) If you want some KISS for v1, just have: contract.call("safeTransferFrom", from, to, tokenId)
contract.estimate_gas(....)
contract.sign(...) |
I didn't find official link. Here is what I've got for https://eips.ethereum.org/EIPS/eip-6093#erc-721: [
{
"inputs": [
{
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
},
{
"internalType": "address",
"name": "owner",
"type": "address"
}
],
"name": "ERC721IncorrectOwner",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "operator",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "ERC721InsufficientApproval",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "approver",
"type": "address"
}
],
"name": "ERC721InvalidApprover",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "operator",
"type": "address"
}
],
"name": "ERC721InvalidOperator",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
}
],
"name": "ERC721InvalidOwner",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "receiver",
"type": "address"
}
],
"name": "ERC721InvalidReceiver",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "sender",
"type": "address"
}
],
"name": "ERC721InvalidSender",
"type": "error"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "ERC721NonexistentToken",
"type": "error"
}
] |
https://soliditylang.org/blog/2021/04/21/custom-errors/
Contract errors are not parsed from ABI by
Contract
class and the revert data is not part ofIOError
to be parsed manually.Example script:
RPC Response:
Thrown error:
The text was updated successfully, but these errors were encountered: