4

Node.js Solidity compiler parses contract and returns its ABI, is there any library to retrieve all declared identifiers in a contract?

For example, the following contract:

contract Person {
    uint id;
    bytes firstName;
    bytes lastName;
}

Should be parsed to:

identifiers: [
  {
    type: "uint",
    name: "id"
  },
  {
    type: "bytes",
    name: "firstName"
  },
  {
    type: "bytes",
    name: "lastName"
  }
]
1

You can use ConsenSys/solidity-parser and walk the resulting AST looking for variable declarations. There are no visitors included in the package, so you will have to write one yourself.

  • And how? As it is currently written it's rather a comment than an answer. – Afr Feb 8 '17 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.