Skip to content
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

Don’t error on the new "error" type in Solidity ABI #1497

Closed
ricmoo opened this issue Apr 22, 2021 · 3 comments
Closed

Don’t error on the new "error" type in Solidity ABI #1497

ricmoo opened this issue Apr 22, 2021 · 3 comments
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@ricmoo
Copy link
Member

ricmoo commented Apr 22, 2021

Solidity has added a new "error" type and the current parser will throw if unknown types are included.

I just need to add '"error"` to the whitelist of fields to ignore in a patch version.

Support for the EIP-838 errors will be added in the next minor version.

@ricmoo ricmoo added enhancement New feature or improvement. on-deck This Enhancement or Bug is currently being worked on. labels Apr 22, 2021
@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels Apr 26, 2021
@ricmoo
Copy link
Member Author

ricmoo commented Apr 26, 2021

This 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. :)

@angelo-di-marzio
Copy link

angelo-di-marzio commented Apr 26, 2021

I still have the error on 5.1.4.
I'm trying to compile the contract using hardhat.

Here is the error :

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)
    at Logger.makeError (ANONYMIZED/testdapp\node_modules\@ethersproject\logger\src.ts\index.ts:205:28)
    at Logger.throwError (ANONYMIZED/testdapp\node_modules\@ethersproject\logger\src.ts\index.ts:217:20)
    at Logger.throwArgumentError (ANONYMIZED/testdapp\node_modules\@ethersproject\logger\src.ts\index.ts:221:21)
    at Function.Fragment.fromObject (ANONYMIZED/testdapp\node_modules\@ethersproject\abi\src.ts\fragments.ts:454:23)
    at Function.Fragment.from (ANONYMIZED/testdapp\node_modules\@ethersproject\abi\src.ts\fragments.ts:435:25)
    at ANONYMIZED/testdapp\node_modules\@ethersproject\abi\src.ts\interface.ts:90:29
    at Array.map (<anonymous>)
    at new Interface (ANONYMIZED/testdapp\node_modules\@ethersproject\abi\src.ts\interface.ts:89:47)
    at Function.BaseContract.getInterface (ANONYMIZED/testdapp\node_modules\@ethersproject\contracts\src.ts\index.ts:774:16)
    at ContractFactory.getInterface (ANONYMIZED/testdapp\node_modules\@ethersproject\contracts\src.ts\index.ts:1228:25) {
  reason: 'invalid fragment object',
  code: 'INVALID_ARGUMENT',
  argument: 'value',
  value: {
    inputs: [ [Object], [Object] ],
    name: 'InsufficientBalance',
    type: 'error'
  }
}

Here is the code that raises that error :

    error InsufficientBalance(uint256 available, uint256 requested);

    constructor() {
        minter = msg.sender;
    }

    function mint(address receiver, uint amount) public {
        require(msg.sender == minter);
        require(amount < 1e60);
        balances[receiver] += amount;
    }

    function send(address receiver, uint amount) public {
        if (amount > balances[msg.sender])
            revert InsufficientBalance({
                available: balances[msg.sender],
                requested: amount
            });

        balances[msg.sender] -= amount;
        balances[receiver] += amount;
        emit Sent(msg.sender, receiver, amount);
    }

I'm not sure what to provide so feel free to ask me more information :)

Edit : It works for you and fragio so i must do something wrong

@angelo-di-marzio
Copy link

I did a fresh install and it seems to work !

@ricmoo ricmoo closed this as completed May 30, 2021
pull bot pushed a commit to shapeshift/ethers.js that referenced this issue Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

2 participants