Guidance for coding agents working in this repo.
This repo is for runnable TypeScript examples that verify Injective SDK behavior and endpoint responses. Keep examples small, direct, and easy to inspect.
- Use
pnpm; do not add Yarn or npm lockfiles. - Preserve the current Injective dependency update workflow unless the user asks
to change it.
pnpm deps:injective:updateis the explicit update command. - Do not run the full
pnpm checkbefore confirming the code structure with the user. - Keep a temporary tracking document under
/private/tmp/injective-ts-examples/while doing multi-step work. - Prefer focused validation while iterating:
pnpm exec tsc --noEmit- targeted
pnpm exec vitest run ... - scoped
pnpm exec eslint ... pnpm example list
- Keep changes intended for review in one clear commit unless the user asks otherwise.
Add one .ts file under src/examples/<category>/.
The runner auto-discovers examples from src/examples, so do not manually add
new examples to a central list.
Do not add individual examples to the main README.md. Keep example-specific
documentation beside the example or in generated runner output.
Each example file must export:
metadata: lightweight example metadata.run: the main async runner function.
Use this shape:
import type { ExampleMetadata } from "../types";
import { runDirectly } from "../../lib/direct-run";
export const metadata: ExampleMetadata = {
id: "query:example-id",
category: "queries",
title: "Example title",
description: "Short description shown by pnpm example list.",
requiresEnvironment: ["PRIVATE_KEY"],
mayBroadcast: false,
};
export const run = async (): Promise<void> => {
const { SomeSdkClient } = await import("@injectivelabs/sdk-ts");
// Example implementation.
};
runDirectly(module, run);- Keep SDK-heavy imports inside
runsopnpm example liststays fast and does not require env vars, endpoint access, or SDK initialization. - Top-level imports should usually be limited to types and local lightweight
helpers like
runDirectly. - Use ids with a category prefix, such as
query:spot-markets,tx:simulate-msg-send,authz:contract-execution, orcosmjs:send-tokens. - Use readable names. Avoid abbreviations in variables and functions.
- Use early returns for guard conditions.
- Use shared env helpers from
src/lib/env.ts; do not cast uncheckedprocess.envvalues. - Keep root
.env.examplefocused on shared variables. Do not pile every example-specific variable into it unless the variable is broadly reused. - For private-key or transaction examples, default to simulation or no-op
behavior. Require
BROADCAST_TRANSACTIONS=truebefore broadcasting. - Errors must be easy to trace. Do not collapse unexpected failures to only
String(error)orerror.message; preserve stack traces and original causes. When adding context, usenew Error("context", { cause: error })or rethrow the original error sorunDirectlycan print the stack and structured details. - Do not make live network calls from tests. Test the runner, registry, metadata, parsing, and env handling without touching endpoints.
When adding or changing examples, add or update focused tests when practical. At minimum, make sure:
pnpm example listdiscovers the example.pnpm exec tsc --noEmitpasses.- Relevant runner/registry tests pass.
- Scoped lint passes for changed files.