35

is there a way with web3.js to get a contract abi json, knowing only the contract address?

I cannot find anymore a link in wich they explain how to do this, in this post the guy replied telling that there is a way to do this but it's not so well documented.

How can I do this?

user2548436
  • 495
  • 2
  • 5
  • 9

4 Answers4

22

a) you know the source code of smart-contract

programmatically: see the link to gist from Ivan's answer

manually: with Remix

b) you don't know the source code but smart-contract was verified in one of the explorers

Then, use block explorer search to get ABI of smart-contract. For example, you can read the verified source code of smart-contracts in BlockScout, Etherscan, Etherchain

c) you don't know the source code && contract is not verified

You can use Panoramix smart-contracts decompiler to get a partial ABI of smart-contract

Victor Baranov
  • 2,027
  • 1
  • 17
  • 31
5

To add to o0ragman0o's comment, see this doc:

https://solidity.readthedocs.io/en/v0.5.2/metadata.html

It outlines how contract metadata should be published to Swarm to avoid centralized (i.e. Etherscan) management/access to contract metadata (including ABI).

Michael Coon
  • 61
  • 1
  • 1
2

I have the same question before. For now is not possible, only you can do it with solc compile. Here is an example : https://gist.github.com/tomconte/4edb83cf505f1e7faf172b9252fff9bf

0

you can always solc then call the abi from a file or directly. source : Solcjs

Tarik EN-NAKDI
  • 92
  • 1
  • 13