shazow / whatsabi

Extract the ABI (and resolve proxies, and get other metadata) from Ethereum bytecode, even without source code.
https://shazow.github.io/whatsabi/
MIT License
1.04k stars 71 forks source link

Invalid JSON output: keys and values missing double quotes #50

Closed alxs closed 1 year ago

alxs commented 1 year ago

I'm running whatsabi on a Macbook Air with M2 chip, node v18.13.0, ethers v6.7.1 and whatsabi v0.7.0.

From the README:

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

const provider = new ethers.getDefaultProvider(); // substitute with your fav provider
const address = "0x00000000006c3852cbEf3e08E8dF289169EdE581"; // Or your fav contract address
const code = await provider.getCode(address); // Load the bytecode

// Get just the callable selectors
const selectors = whatsabi.selectorsFromBytecode(code);
console.log(selectors); // -> ["0x06fdde03", "0x46423aa7", "0x55944a42", ...]

// Get an ABI-like list of interfaces
const abi = whatsabi.abiFromBytecode(code);
console.log(abi);
// -> [
//  {"type": "event", "hash": "0x721c20121297512b72821b97f5326877ea8ecf4bb9948fea5bfcb6453074d37f"},

Instead, this same code produces the following invalid JSON:

[
  '0x06fdde03', '0x46423aa7',
  '0x55944a42', '0x5b34b966',
  ...
]

[
  {
    type: 'function',
    selector: '0x06fdde03',
    ...
  }
]
shazow commented 1 year ago

Just to confirm what's going on -- console.log(...) will format and truncate javascript objects, like in the example. If you need JSON, you'll need to JSON.stringify(output). Is that what you're doing?

alxs commented 1 year ago

Yes. It just seemed like that was the intended output from the README. If it's intentional, please disregard this issue or take it as a suggestion to use console.log(JSON.stringify(abi)) in the examples.

shazow commented 1 year ago

👍