shazow / whatsabi

Extract the ABI (and other metadata) from Ethereum bytecode, even without source code.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalid JSON output: keys and values missing double quotes

alxs opened this issue · comments

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',
    ...
  }
]

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?

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.