Today Solidity 0.8.4 was released and it includes a new feature called "custom errors" that currently breaks Ethers.js.
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.4;
contract TestToken {
error InsufficientBalance(uint256 available, uint256 required);
function transfer(address /*to*/, uint amount) public pure {
revert InsufficientBalance(0, amount);
}
}
The resulting ABI contains a new type of fragment for errors:
{
"type": "error",
"name": "InsufficientBalance",
"inputs": [
{
"internalType": "uint256",
"name": "available",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "required",
"type": "uint256"
}
],
},
Loading the contract ABI on Ethers results in:
Error: invalid fragment object (argument="value", value={"inputs":[{"internalType":"uint256","name":"available","type":"uint256"},{"internalType":"uint256","name":"required","type":"uint256"}],"name":"InsufficientBalance","type":"error"}, code=INVALID_ARGUMENT, version=abi/5.1.1)
Eventually Ethers should parse the revert data into one of these error objects but in the meantime it should still support loading these ABIs.
Sorry, just saw this. I鈥檝e opened up enhancement issues to track this and will be adding support soon. :)
Being tracking in #1497 and #1498.
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! :)
Most helpful comment
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. :)