Support custom errors from Solidity 0.8.4 (new fragment type)
See original GitHub issueToday 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.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Custom Errors in Solidity
Custom errors are defined using the error statement, which can be used inside and outside of contracts (including interfaces and libraries).
Read more >Interface - Ethers.js
The Interface Class abstracts the encoding and decoding required to interact with contracts on the Ethereum network. Many of the standards organically ...
Read more >ethereum/remix-dev - Gitter
Hi, Does anyone know if REMIX has a helpline? that you can actually talk with someone for tech support if you have a...
Read more >How to test the Solidity fallback() function via Hardhat?
Then instantiate a new smart contract object. ... const fakeDemoContract = new ethers. ... demoContract.interface.fragments, `function ...
Read more >Error | Solidity 0.8 - YouTube
Solidity has 3 ways to throw an error: require, revert and assert. From Solidity 0.8 custom errors can be declared.# Solidity #SmartContract ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Seems to work!
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. 😃