Skip to Content
ReferenceCLIInit

Init

Create a contract.dev.{js,cjs} config file in the current directory. Every other CLI command reads this file to find your Stagenet’s RPC URL.

Usage

contract.dev init contract.dev init --rpc-url=<YOUR_STAGENET_RPC_URL> contract.dev init --force
FlagDescription
--rpc-url=<url>Optional. Fill in the RPC URL up front. Omit to write a placeholder you’ll edit by hand.
--force, -fOverwrite an existing contract.dev.{js,cjs} instead of erroring.

The file written looks like:

/** @type {import('contract.dev').Config} */ module.exports = { rpcUrl: "<YOUR_STAGENET_RPC_URL>", };

Get your Stagenet RPC URL from your project dashboard at contract.dev.

CommonJS vs ESM

The CLI picks the extension based on the nearest package.json:

  • package.json does not set "type": "module" → writes contract.dev.js
  • package.json sets "type": "module" → writes contract.dev.cjs

The loader uses require(), so .cjs is needed in ESM projects to avoid Node’s “Must use import to load ES Module” error.

Errors

contract.dev.js already exists Use --force to overwrite.

If either contract.dev.js or contract.dev.cjs already exists, init refuses to write — re-run with --force to overwrite. The CLI never creates both side-by-side.

contract.dev.{js,cjs} is a regular Node module loaded with require(). You can use env vars, path.join, imports, and template literals to compute paths or pull the RPC URL from secrets — see Dynamic paths for examples.

Available fields

interface Config { rpcUrl?: string; contracts?: string; // override Foundry/Hardhat source dir artifacts?: string; // override Foundry/Hardhat compiled-artifacts dir }

contracts and artifacts are only needed when the CLI can’t auto-detect them from foundry.toml / hardhat.config — see import-contracts.

Last updated on