question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support custom errors from Solidity 0.8.4 (new fragment type)

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
frangiocommented, Apr 26, 2021

Seems to work!

2reactions
ricmoocommented, Apr 26, 2021

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. 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found