question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Retrieve ABI from sourcify / metadata

See original GitHub issue

Since you, @krzkaczor , mentioned that you would like to retrieve the ABI directly from the metadata as well instead of from etherscan, I just want to quickly explain the steps. We are working on an npm package to maybe do part of this, but it’s really not complicated (pseudocode):

code = eth.getCodeAt(addr).hexToBytes()
metadataSize = code[-2] * 0x100 + code[-1]
metadataCBOR = cbor.decode(code[-metadataSize - 2:-2])
ipfsLink = metadataCBOR['ipfs']
// the link is binary-encoded, you might have to base58-encode it, depending on the
// way you access ipfs
metadata = ipfs.retrieve(ipfsLink)
abi = metadata['output']['abi']

This is the recommended decentralized way to do it. You can either use ipfs “directly” or through an http gateway. My experience with http gateways (at least the cloudfront one) is that they will also pin data that is retrieved through them, which is nice.

The access via ipfs only works if contracts are fully verified on sourcify (including the correct metadata hash). This guarantees that neither the source nor the ABI have been modified after deployment.

There is a centralized http interface to sourcify that also allows you to access partially verified contract’s abis: https://github.com/ethereum/sourcify/blob/master/docs/api/server/getByChainAndAddress.md

If you have further questions, you can also come to our gitter / matrix channel: https://gitter.im/ethereum/source-verify

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
krzkaczorcommented, Nov 19, 2021

Basic support for sourcify got released in: https://github.com/dethcrypto/eth-sdk/releases/tag/%40dethcrypto%2Feth-sdk%400.2.2

Currently, it uses sourcify API (backend), we could migrate to IPFS once npm package is done and exposes a simple interface for us to use.

1reaction
kuzdogancommented, Oct 18, 2021

I’m not in Lisbon but @chriseth is there so you might bump into each other. I think it’s more or less clear and seems to be quite parallel with what we want to build. I will be letting you know about the progress, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Verify Contracts Perrrrrfectly: Why and How? | Sourcify Docs
The metadata file is a JSON document that looks like this and contains information on two things: How to interact with the contract:...
Read more >
All you need to know about Sourcify
The metadata file contains information about the compiled contract, e.g. the used compiler version, the sources used, the ABI and the ...
Read more >
How to view contract source code from ABI, address and ...
Only bytecode is stored on the blockchain so you won't get it ... check the Sourcify contract repository to see if the contract...
Read more >
ethereum/source-verify
This is the error that i get both from remix and sourcify. ... Could you maybe share the contract source code and metadata?...
Read more >
All you need to know about Sourcify
checks that it is the same as the deployed code. permanently stores the source code, ABI and other metadata on IPFS. How is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found