Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

abigen! fails with confusing error on solidity output #476

Closed
petertdavies opened this issue Sep 28, 2021 · 2 comments · Fixed by #478 or #480
Closed

abigen! fails with confusing error on solidity output #476

petertdavies opened this issue Sep 28, 2021 · 2 comments · Fixed by #478 or #480
Labels
bug Something isn't working

Comments

@petertdavies
Copy link
Contributor

Version

└── ethers v0.5.3
    ├── ethers-contract v0.5.3
    │   ├── ethers-contract-abigen v0.5.3
    │   │   ├── ethers-core v0.5.4
    │   ├── ethers-contract-derive v0.5.3
    │   │   ├── ethers-contract-abigen v0.5.3 (*)
    │   │   ├── ethers-core v0.5.4 (*)
    │   ├── ethers-core v0.5.4 (*)
    │   ├── ethers-providers v0.5.4
    │   │   ├── ethers-core v0.5.4 (*)
    ├── ethers-core v0.5.4 (*)
    ├── ethers-middleware v0.5.3
    │   ├── ethers-contract v0.5.3 (*)
    │   ├── ethers-core v0.5.4 (*)
    │   ├── ethers-providers v0.5.4 (*)
    │   ├── ethers-signers v0.5.3
    │   │   ├── ethers-core v0.5.4 (*)
    ├── ethers-providers v0.5.4 (*)
    └── ethers-signers v0.5.3 (*)

Platform

Linux 5.4.0-81-generic #91-Ubuntu SMP Thu Jul 15 19:09:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

The bug

The abigen! macro fails with the confusing error: Illegal abi `{` , when called on the output of the solidity compiler (rather than just the abi). Here is a minimal example.

use ethers::prelude::*;

abigen!(
    Foo,
    "npm:@openzeppelin/contracts@2.5.0/build/contracts/IERC20.json"
);

fn main() {
    println!("Hello, world!");
}

The reason

The output of the solidity compiler isn't just the abi in JSON format, it is a larger JSON object with an abi key containing the abi. When the abi parser attempts to parse this it fails, falling back to the human readable parser which then fails with error: Illegal abi `{` .

It would be nice if we could support both formats.

@petertdavies petertdavies added the bug Something isn't working label Sep 28, 2021
@mattsse
Copy link
Collaborator

mattsse commented Sep 28, 2021

You're probably right, I also suspect that this happens because abigen! expects the abi object as root of the json like contract_abi.json
this is not the case for builds like openzeppelin: https://npm.runkit.com/@openzeppelin/contracts/build/contracts/IERC20.json?t=1632833791195
So we probably need to account for that when decoding from npm.

@gakonst
Copy link
Owner

gakonst commented Sep 28, 2021

Ugh I was sort of opinionated on not parsing the artifacts, but that seems inevitable given that OZ has published packages like that. We should add that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
3 participants