subsquid / squid-sdk

The main repo of the squid SDK
Apache License 2.0
1.22k stars 151 forks source link

squid-evm-typegen 1.3.1 fails with "TypeError: abi.map is not a function" #129

Closed abernatskiy closed 1 year ago

abernatskiy commented 1 year ago

Attempted to use the tool with two smart contracts (0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9, the AAVEv2 pool, and 0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413 from this example), fails with

evm-typegen error: TypeError: abi.map is not a function

To Reproduce Steps to reproduce the behavior:

  1. Make a test directory and cd to it
  2. Run npm install @subsquid/evm-typegen
  3. Fetch the abi with
    $ curl "https://api.etherscan.io/api?module=contract&action=getabi&address=0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413" --output abi.json
  4. Run npx squid-evm-typegen --abi abi.json --output abi.ts
  5. See the error. Note that abi.ts is not generated.

Expected behavior Successful generation of abi.ts

Environment (please complete the following information):

Additional context Retrieved abi.json

belopash commented 1 year ago

Fetched abi has incorrect format

abernatskiy commented 1 year ago

Ah I see, abi.json is expected to be cleaned up from etherscan metadata. If I do so via

$ python -c "import json; ifile=open('abi.json', 'r'); print(json.load(ifile)['result']); ifile.close()" > abi2.json

then

$ npx squid-evm-typegen --abi abi2.json --output abi2.ts

works.

Thanks.

belopash commented 1 year ago

We discussed about "etherscan abi fetch" feature, but not sure if we will implement it.

abernatskiy commented 1 year ago

It's not strictly necessary, we'll just have to update the docs with the additional steps. Also, I just discovered EIP-1967 and in light of it etherscan abi fetching will have to be made somewhat more complicated anyway.

abernatskiy commented 1 year ago

It would be nice to detect etherscan abi format and give user a hint instead of an opaque error message.