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

support 4bytes or similar db #278

Open
naps62 opened this issue Jun 29, 2023 · 4 comments
Open

support 4bytes or similar db #278

naps62 opened this issue Jun 29, 2023 · 4 comments
Labels
epic A high-level tracker for a broad feature

Comments

@naps62
Copy link
Member

naps62 commented Jun 29, 2023

title self explanatory. we want to decode transaction calldata without relying solely on known ABIs

@naps62 naps62 added the epic A high-level tracker for a broad feature label Jun 29, 2023
@naps62 naps62 added this to the Developer Experience milestone Jun 29, 2023
@shazow
Copy link

shazow commented Sep 8, 2023

Just spelunking through some iron-wallet issues. WhatsABI doesn't have calldata decoding yet (hmm should I add it, or is that too out of scope?), but we do have some nice 4byte db loaders:

import { whatsabi } from "@shazow/whatsabi";

const signatureLookup = new whatsabi.loaders.OpenChainSignatureLookup();
const signatures = await signatureLookup.loadFunctions("0x06fdde03");
...

Also support 4byte.directory and also compound loaders (try each one until a result is found).

@naps62
Copy link
Member Author

naps62 commented Sep 8, 2023

hi there 👋🏼

hmm, I'm not familiar enough to know if it would be out of scope. but (correct if I'm wrong), using your snippet above I should just be able to load the resulting signature into viem to handle calldata decoding?

@shazow
Copy link

shazow commented Sep 8, 2023

Yea! You'd use something like parseAbiItem on the first result (it'll give you all the candidates, but first one is usually most common), that gives you the abi that you can parse the rest of the calldata from.

Would be a nice recipe to add to the WhatsABI docs... 🤔

@shazow
Copy link

shazow commented Sep 8, 2023

Haven't tested it but I imagine it something like this:

import { whatsabi } from "@shazow/whatsabi";
import { decodeFunctionData, parseAbi } from "viem";

const calldata = "...";
const selector = calldata.slice(0, 10);

const signatureLookup = new whatsabi.loaders.OpenChainSignatureLookup();
const signatures = await signatureLookup.loadFunctions(selector);
if (signatures.length === 0) { throw "/shrug"; }
const abi = parseAbi([signatures[0]]);

const { functionName, decodedArgs } = decodeFunctionData({
  abi,
  data: calldata,
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
epic A high-level tracker for a broad feature
Projects
None yet
Development

No branches or pull requests

2 participants