Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve ABI from sourcify / metadata #9

Closed
chriseth opened this issue Oct 8, 2021 · 9 comments
Closed

Retrieve ABI from sourcify / metadata #9

chriseth opened this issue Oct 8, 2021 · 9 comments
Assignees
Projects

Comments

@chriseth
Copy link

chriseth commented Oct 8, 2021

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

@krzkaczor
Copy link
Member

@chriseth thanks! This is a huge help. I'll make sure to prioritize this issue.

@kuzdogan
Copy link

We were thinking about implementing this as an npm package ethereum/sourcify#538 This is also what you will need right? We might want to sync on this so we won't do the same thing separately.

The main goal was to return the decoded the parameters either using the ABI or the userdoc if available but an additional method that will return the ABI should be useful.

@krzkaczor
Copy link
Member

@kuzdogan yes definately! NPM package woudl be great. It's not top prority for us now but will gonna do it in a month or so. If you want some feedback from us, we can hop on a call or meet somewhere in Lisbon. Your call.

@kuzdogan
Copy link

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!

@kuzdogan
Copy link

@krzkaczor we have an initial working package and would love to have some feedback if you'd have time and to better understand what you'd need 🙂 How should I contact you?

@krzkaczor
Copy link
Member

@kuzdogan Perfect! I am @krzkaczor on telegram.

@hasparus hasparus self-assigned this Nov 10, 2021
@krzkaczor
Copy link
Member

@hasparus did initial implementation in #42

@kuzdogan first big piece of feedback is that we need s CJS build instead of ESM. You should support both in your package IMO.

@kuzdogan
Copy link

Thanks, these are valuable feedback. I agree that they should both be available. We'll look into it.

Let me know if you have any other remarks, both on the package or Sourcify in general. @hasparus @krzkaczor

@krzkaczor
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
eth-sdk
Awaiting triage
Development

No branches or pull requests

4 participants