This package has two public surfaces driven from the same source data:
- The npm package
@polygonlabs/meta— typedas constABI modules under./abi/*, typed network metadata under./info/*, plus raw JSON under./network/*. - The public HTTP endpoint at
https://static.polygon.technology/...— same JSON files served verbatim by an nginx Docker image.
The single source of truth for both is the JSON tree under network/.
Adding a new ABI or network means dropping JSON files into network/;
the typed TS modules are codegenned at build time.
The repo-root network/ directory is the single source of truth. It
feeds both the npm package (via scripts/codegen.ts) and the
static.polygon.technology nginx image (via Dockerfile).
- Get the ABI as JSON from your build pipeline (foundry, hardhat,
solc, Etherscan). The expected shape is
{ "abi": [...] }. - Drop it at
<repo-root>/network/<chain>/<version>/artifacts/<type>/<ContractName>.jsonwhere<chain>ismainnetortestnet,<version>is the network identifier (v1,cherry,amoy,cardona), and<type>is the artifact bucket (pos,plasma,fx-portal,genesis,zkevm). - From inside
packages/meta/, runpnpm run codegen. The script:- Reads
<repo-root>/network/networks.json(the canonical registry) and walks each<chain>/<version>/referenced there. - Emits
src/generated/abi/<...>.tsandsrc/generated/info/<...>.tsasexport const ... = ... as const;modules. - Mirrors the entire
<repo-root>/network/tree intopackages/meta/network/so the@polygonlabs/meta/network/*subpath export resolves to the same paths consumers of@maticnetwork/meta@2.xalready use. - Hard-errors on a missing
index.json, missingartifacts/directory, missing JSON files under a type, or any entry innetworks.jsonwhose tree is incomplete — silent skips here would publish a package whose codegen is out of sync with the JSON.
- Reads
- Run
pnpm run build(codegen +tsc -p tsconfig.build.json) to verify the emitted.d.tscarries theas consttuple type. - Commit both the JSON in
<repo-root>/network/and the regenerated files underpackages/meta/src/generated/in the same commit. The PR gate runscodegen-drift-check(regenerate, thengit diff --exit-code) and fails when the two disagree..gitattributesmarkspackages/meta/src/generated/**aslinguist-generatedso GitHub collapses it in the PR diff by default.packages/meta/network/is gitignored — it is a pure publish artifact rebuilt byprepackbeforepnpm publish. - Add a changeset describing the addition (
pnpm exec changeset add).
Don't hand-edit anything under src/generated/. It is tracked
(so reviewers can see exactly what ships) but regenerated by
pnpm run codegen. The only authored surface is the JSON in
<repo-root>/network/; the typed TS modules are codegenned.
While editing JSON under network/, run pnpm run codegen:watch in a
side terminal — src/generated/ re-emits within ~200 ms of each save,
keeping in-editor types accurate without a manual rebuild.
-
Drop a
<repo-root>/network/<chain>/<version>/index.jsonwith the network metadata (match the shape used by sibling networks). -
Drop ABI JSON files under
<repo-root>/network/<chain>/<version>/artifacts/<type>/...per "Adding a new ABI" above. -
Append an entry to
<repo-root>/network/networks.json:{ "network": "<chain>", "version": "<version>" } -
Run
pnpm run codegenandpnpm run build. -
Add a changeset.
Each generated ABI module looks like:
export const abi = [...] as const;The as const is load-bearing, not stylistic — without it,
TypeScript widens the array element type to a generic shape and
viem/wagmi/abitype consumers lose the ability to infer function
names, argument types, and return types at the call site. The
codegen script always emits the as const automatically; if you
ever need to extend the codegen, preserve it.
pnpm run codegen # emit src/generated/**.ts from network/
pnpm run build # codegen + tsc → dist/prepack runs build, so pnpm pack and pnpm publish always emit
a fresh dist.
codegen runs the script directly with node scripts/codegen.ts,
which relies on Node's native TypeScript execution — so building
this package requires Node 24. That requirement is declared in
devEngines.runtime.
The published package, however, is pure data: every module under
dist/generated/** is an export const ... = [...] as const literal
with no runtime code, so it runs on any Node that supports ESM subpath
exports. engines.node is therefore set to >=20 to describe the
consumer runtime, not the build toolchain. Don't raise it to match the
build requirement — that would force a Node 24 floor on downstream SDKs
(e.g. @polygonlabs/pos-sdk) that legitimately target Node 20 for no
runtime reason.
This repo uses Changesets
for versioning. Open a PR with a .changeset/<name>.md file describing
the user-visible change. Merging the PR opens a "Version Packages" PR
that bumps the version and writes the changelog. Merging that PR
publishes to npm and tags the release. Do not run
pnpm exec changeset publish manually, and do not run npm publish
directly.
The Docker image that serves static.polygon.technology is built and
deployed via the existing GitHub Actions workflows
(.github/workflows/deployment.yml, deployment_gcp.yml,
build_and_deploy.yml) on every push to master. Those workflows
copy the network/ JSON tree into nginx and ship it. They are
out of scope for this contribution guide; nothing in network/
needs special treatment to be served.