-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 custom errors from Solidity 0.8.4 (new fragment type) #1493
Comments
Sorry, just saw this. I’ve opened up enhancement issues to track this and will be adding support soon. :) |
Not erroring should be fixed in [5.1.4])https://github.com/ethers-io/ethers.js/releases/tag/v5.1.4). Try it out and let me know. :) |
Seems to work! |
Awesome. I'll close this issue, and use #1498 to track the v5.2 release with full Custom Error support. Thanks! :) |
Hi, I supposed custom errors should work thanks to this issue, yet I cannot get them. I have a simple contract: pragma solidity ^0.8.4;
error Invalid (uint256 a, uint256 b);
contract Test {
function compare(uint256 a, uint256 b) public view {
if (a < b) {
revert Invalid({a: a, b: b});
}
}
} And I have a simple script: const ethers = require("ethers");
const ABI = require("./abi.json");
const provider = new ethers.providers.JsonRpcProvider("http://localhost:8545");
const contract = new ethers.Contract(
<CONTRACT_ADDRESS>,
ABI,
provider
);
(async () => {
await contract.compare(0, 1);
})(); ABI[
{
"inputs": [
{
"internalType": "uint256",
"name": "a",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "b",
"type": "uint256"
}
],
"name": "Invalid",
"type": "error"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "a",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "b",
"type": "uint256"
}
],
"name": "compare",
"outputs": [],
"stateMutability": "view",
"type": "function"
}
] No matter which version of {"jsonrpc":"2.0","id":44,"error":{"code":-32600,"message":"execution was reverted"}} |
@sebastiendan In v6, it should definitely work well. What backend are you using? Geth? Can you add |
@ricmoo I'm using a polygon-edge chain. With
With
|
Ethers v5.1 definitely doesn’t support it, as custom errors came out afterwards, but the most recent v5 version should handle them fine. I’m most concerned with v6; the part I need is masked (the |
With
With Open here
|
@sebastiendan It looks like your node (polygon-edge) isn't returning the error data at all, so there is nothing for ethers to process. All it returned was:
It needs to return the encoded error information to be decoded. Maybe you can open a bug or feature request with them? |
@ricmoo I'll do that. |
Today Solidity 0.8.4 was released and it includes a new feature called "custom errors" that currently breaks Ethers.js.
The resulting ABI contains a new type of fragment for errors:
Loading the contract ABI on Ethers results in:
Eventually Ethers should parse the revert data into one of these error objects but in the meantime it should still support loading these ABIs.
The text was updated successfully, but these errors were encountered: