chain-devkit
v1.0.0
Published
Local blockchain development bootstrap: generates a dev secp256k1 keypair and network config on install, plus viem-based RPC client helpers.
Maintainers
Readme
chain-devkit
Local blockchain development bootstrap. On npm install, it:
- Generates a secp256k1 dev account and writes it to
.env. - Writes a
chain.config.yamlnetwork config — fetched from a remote default if reachable, otherwise falls back to a local node config (127.0.0.1:8545, chain ID1337).
It also exposes a small set of viem-based helpers so the generated account is immediately usable against a local RPC.
⚠️ Development use only. The generated key is written in plaintext to
.envon your machine and is meant for local testing against a dev/test chain (e.g. Anvil, Hardhat Network). Never fund it with real assets or use it on mainnet.
Install
npm install chain-devkitThis runs the postinstall step described above. Both .env and chain.config.yaml are generated once — if either file already exists, generation is skipped so re-running npm install won't overwrite an account you're already using.
Usage
const {
getDevAccount,
getConfig,
getPublicClient,
getWalletClient,
getBalance,
sendEth,
} = require("chain-devkit");
// Raw values
const { privateKey, publicKey } = getDevAccount();
const config = getConfig(); // { network, rpcUrl, chainId }
// Balance of the generated dev account
const balance = await getBalance();
// Send ETH from the dev account
const txHash = await sendEth({ to: "0xRecipient...", valueEth: "0.1" });API
| Function | Description |
| --- | --- |
| getDevAccount() | Returns { privateKey, publicKey } (hex, no 0x prefix) read from .env. |
| getConfig() | Returns the parsed chain.config.yaml (network, rpcUrl, chainId). |
| getChain() | Returns a viem Chain object built from getConfig(). |
| getDevSigner() | Returns the dev account as a viem Account (via privateKeyToAccount). |
| getPublicClient() | Returns a viem PublicClient for the configured RPC. |
| getWalletClient() | Returns a viem WalletClient signing with the dev account. |
| getBalance(address?) | Balance of address, defaulting to the dev account. |
| sendEth({ to, valueEth }) | Sends ETH from the dev account to to. |
All of these expect a chain to actually be reachable at rpcUrl (e.g. run anvil or npx hardhat node locally) — the config alone doesn't start a node for you.
Config resolution
chain.config.yaml is generated once, on first install:
postinstallrequestshttps://chain-devkit.com/config(3s timeout).On success, that YAML response becomes your config.
On any failure (timeout, network error, bad response), it falls back to:
network: local rpcUrl: http://127.0.0.1:8545 chainId: 1337
Edit chain.config.yaml directly at any time to point at a different network — it's only generated when the file doesn't already exist.
License
MIT
