Ethers.js: How to get the ABI from a contract address

Created on 28 Feb 2018  路  6Comments  路  Source: ethers-io/ethers.js

Hi,
How can I get the ABI code from a contract address? There is a function to do that?

discussion

All 6 comments

The ABI must be provided by the contract deployer, and cannot be (effectively) derived from just the address or the code at the address.

Often you can find the ABI published by the author by looking at the "code" tab on etherscan.io for the contract address.

Another option (which is highly under utilized) is the ABI can be stored in ENS for a given name.

Sorry if it isn't very helpful a response, but you basically will have to find the ABI from the contract author. :s

I'm closing this, but if you have any further questions, please feel free to re-open. :)

I mean, with the etherscan api, we can retrieve the abi. Is it possible to do it directly with etherjs?

Only contracts that have had their source published and verified can have their ABI downloaded directly. This is something that might be worth adding to the EtherscanProvider as a convenience in the future, but as of now it cannot. Does Etherscan provide a public API for grabbing contract ABI?

Also, contract ABI may be stored in ENS, which is a more reliable way of associating data with a contract. I plan to put something together to help get more widespread adoption of using ENS, since then you could get both the address and ABI simply from a name like registrar.firefly.eth. :)

Only contracts that have had their source published and verified can have their ABI downloaded directly. This is something that might be worth adding to the EtherscanProvider as a convenience in the future, but as of now it cannot. Does Etherscan provide a public API for grabbing contract ABI?

I think we can do it here: https://etherscan.io/apis#contracts
Also, contract ABI may be stored in ENS, which is a more reliable way of associating data with a contract. I plan to put something together to help get more widespread adoption of using ENS, since then you could get both the address and ABI simply from a name like registrar.firefly.eth. :)

That would be so nice!

That API has a lot of restrictions for now, so I may add those endpoints as an Ancillary package instead of part of the regular EtherscanProvider, but it depends how much code it ends up being.

It may make more sense to include as part of the @ethersproject/cli package, which includes a Solidity compiler, which may be necessary for parts of validation, but could wrap it up in a nice API.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

moshebeeri picture moshebeeri  路  3Comments

dave-dm picture dave-dm  路  3Comments

jochenonline picture jochenonline  路  3Comments

dagogodboss picture dagogodboss  路  3Comments

adamdossa picture adamdossa  路  3Comments