{"id":49401,"library":"solidity-ast","title":"solidity-ast","description":"Solidity AST schema, TypeScript type definitions, and utility functions for traversing and querying Solidity compiler ASTs. Current stable version is 0.4.62. Released as needed to support new Solidity versions. Key differentiators: auto-generated types from JSON Schema, type-safe helpers like isNodeType, findAll, astDereferencer, and srcDecoder. Works with Solidity >=0.6.6 (mostly compatible down to 0.5.0).","status":"active","version":"0.4.62","language":"javascript","source_language":"en","source_url":"https://github.com/OpenZeppelin/solidity-ast","tags":["javascript","typescript"],"install":[{"cmd":"npm install solidity-ast","lang":"bash","label":"npm"},{"cmd":"yarn add solidity-ast","lang":"bash","label":"yarn"},{"cmd":"pnpm add solidity-ast","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"TypeScript types are exported as types only; use `import type` for compile-time only, or `import { SourceUnit }` if you need it as a value (not recommended). Since it's a type-only import, it's erased at runtime.","wrong":"const { SourceUnit } = require('solidity-ast')","symbol":"SourceUnit","correct":"import type { SourceUnit } from 'solidity-ast'"},{"note":"Utility functions are not in the main package; they must be imported from 'solidity-ast/utils'.","wrong":"import { isNodeType } from 'solidity-ast'","symbol":"isNodeType","correct":"import { isNodeType } from 'solidity-ast/utils'"},{"note":"findAll is a generator function; loop over it with `for...of` or spread into an array. Second argument is the root AST node; third optional argument is a prune function.","wrong":"import { findAll } from 'solidity-ast'","symbol":"findAll","correct":"import { findAll } from 'solidity-ast/utils'"},{"note":"astDereferencer returns a function that takes (nodeType, id) and returns the node. For CommonJS, use `const { astDereferencer } = require('solidity-ast/utils');`.","wrong":"const { astDereferencer } = require('solidity-ast/utils');","symbol":"astDereferencer","correct":"import { astDereferencer } from 'solidity-ast/utils'"}],"quickstart":{"code":"import type { SourceUnit, ContractDefinition } from 'solidity-ast';\nimport { isNodeType, findAll } from 'solidity-ast/utils';\n\n// Example: parse a Solidity source and traverse AST\n// Assuming you have the AST from solc output\nconst sourceUnit: SourceUnit = {\n  nodeType: 'SourceUnit',\n  nodes: [\n    {\n      nodeType: 'ContractDefinition',\n      name: 'MyContract',\n      abstract: false,\n      fullyImplemented: true,\n      linearizedBaseContracts: [],\n      baseContracts: [],\n      nodes: [],\n    },\n  ],\n};\n\n// Check node type and narrow\nif (isNodeType('ContractDefinition', sourceUnit.nodes[0])) {\n  console.log((sourceUnit.nodes[0] as ContractDefinition).name);\n}\n\n// Iterate all ContractDefinitions\nfor (const contractDef of findAll('ContractDefinition', sourceUnit)) {\n  console.log(contractDef.name);\n}\n","lang":"typescript","description":"Shows importing types from solidity-ast and using isNodeType and findAll utilities to traverse a Solidity AST."},"warnings":[{"fix":"Use `import { ... } from 'solidity-ast/utils'` for isNodeType, findAll, astDereferencer, srcDecoder.","message":"Utility functions must be imported from 'solidity-ast/utils', not from 'solidity-ast'.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Pin to the latest version of solidity-ast and check compatibility with your Solidity version. The package states it's accurate for >=0.6.6.","message":"The AST types are generated from the JSON Schema and may not cover all edge cases or newer Solidity features immediately.","severity":"gotcha","affected_versions":"<0.5.0"},{"fix":"Always test after upgrade and consult the changelog or diffs on the NPM package.","message":"Breaking changes may occur between minor versions if the Solidity AST structure changes. No explicit semver guarantee for AST shape.","severity":"breaking","affected_versions":">=0.0.0"},{"fix":"Use the types for traversal but be aware that some node types or fields may be missing or inaccurate.","message":"Some older Solidity versions (<0.6.0) may have incomplete type coverage.","severity":"deprecated","affected_versions":"<0.5.0"},{"fix":"Always pass the complete solc output object (the entire JSON from solc standard JSON input/output).","message":"astDereferencer requires the full solc output (with all source files' ASTs). Passing only a single source unit will not work.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.4.62':24 '0.5.0':60 '0.6.6':55 'ast':3,5,19 'astdereferenc':49 'auto':36 'auto-gener':35 'compat':57 'compil':18 'current':20 'definit':9 'differenti':34 'findal':48 'function':12 'generat':37 'helper':45 'isnodetyp':47 'javascript':61 'json':40 'key':33 'like':46 'most':56 'need':27 'new':30 'queri':16 'releas':25 'safe':44 'schema':6,41 'solid':2,4,17,31,54 'solidity-ast':1 'srcdecod':51 'stabl':21 'support':29 'travers':14 'type':8,38,43 'type-saf':42 'typescript':7,62 'util':11 'version':22,32 'work':52","created_at":"2026-06-07T17:01:35.957437+00:00","updated_at":"2026-06-07T17:01:35.957437+00:00","problems":[{"fix":"Change import to: `import { isNodeType } from 'solidity-ast/utils'`","cause":"Importing from wrong path (solidity-ast instead of solidity-ast/utils).","error":"TypeError: isNodeType is not a function"},{"fix":"Use `import type { SourceUnit } from 'solidity-ast'` in TypeScript, or `const { SourceUnit } = require('solidity-ast')` is incorrect because it's a type-only export.","cause":"Trying to import SourceUnit as a value in a JavaScript file or with `require` in TypeScript without `type` keyword.","error":"Module '\"solidity-ast\"' has no exported member 'SourceUnit'."},{"fix":"Update to latest version of solidity-ast and ensure your tsconfig includes `node` moduleResolution or `node16`.","cause":"Missing type declaration for the utility subpath; older versions of TypeScript may not resolve it, or package.json exports missing.","error":"Cannot find module 'solidity-ast/utils' or its corresponding type declarations."},{"fix":"Ensure the object has all required fields like `nodeType: 'SourceUnit'`, `nodes`, etc. Use the defined types.","cause":"Passing an empty object where a full SourceUnit object is expected.","error":"Type '{}' is not assignable to type 'SourceUnit'."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://solidity-ast.info/","github":"https://github.com/OpenZeppelin/solidity-ast","docs":null,"changelog":null,"pypi":null,"npm":"solidity-ast","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}