This package exists to help you develop on top of the Codex API (https://docs.codex.io).
It provides generated TypeScript types and convenient methods to access the GraphQL API with full type safety.
Note
We've changed our name from Defined to Codex.
You will see references to our previous company name, Defined, while we make the switch to Codex.
- 🚀 Fully Typed: Generated TypeScript types for all GraphQL operations
- 📦 Tree Shakeable: ESM support with optimized bundle size
- 🔄 Real-time: WebSocket subscriptions support
- 🛠 Developer Friendly: Comprehensive examples and documentation
| Package Manager | Command |
|---|---|
| npm | npm install @codex-data/sdk |
| yarn | yarn add @codex-data/sdk |
| pnpm | pnpm add @codex-data/sdk |
Follow one of the examples in the examples directory, or simply run.
Fetch a token.
import { Codex } from "@codex-data/sdk";
const sdk = new Codex(MY_API_KEY);
sdk.queries
.token({
input: {
address: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
networkId: 56,
},
})
.then(console.log);Use your own GraphQL selections
import { Codex } from "@codex-data/sdk";
const sdk = new Codex(process.env.CODEX_API_KEY || "");
// Using the raw GraphQL client
sdk
.send<{ getNetworks: Array<{ id: string; name: string }> }>(
`
query GetNetworks {
getNetworks { id name }
}
`,
{},
)
.then((res) => {
console.log("Networks: ", res.getNetworks);
});Subscribe to real-time data
import { Codex } from "@codex-data/sdk";
const sdk = new Codex(process.env.CODEX_API_KEY || "");
// Subscribe to price updates
sdk.subscriptions.onPriceUpdated(
{
address: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
networkId: 56,
},
(result) => {
if (result.data) {
console.log("Price updated:", result.data.onPriceUpdated);
}
},
);# Install dependencies
pnpm install
# Build the SDK
pnpm run buildAll examples require a Codex API key. Get your API key at docs.codex.io.
Basic usage with inline GraphQL queries:
cd examples/simple
pnpm install
CODEX_API_KEY=your_api_key pnpm run devShows how to use GraphQL Code Generator for fully typed queries:
cd examples/codegen
pnpm install
pnpm run codegen
CODEX_API_KEY=your_api_key pnpm run devFull-stack example with a Next.js application:
cd examples/next
pnpm install
NEXT_PUBLIC_CODEX_API_KEY=your_api_key pnpm run devThe SDK is built with modern tooling and provides both CommonJS and ESM builds:
@codex-data/sdk/
├── dist/
│ ├── index.js # CommonJS entry point
│ ├── index.mjs # ESM entry point
│ ├── index.d.ts # TypeScript definitions
│ └── sdk/ # SDK implementation
├── README.md
└── package.json
We welcome contributions! Please feel free to submit a Pull Request.
pnpm run build- Build the SDK for productionpnpm run test- Run the test suitepnpm run lint- Lint the codebasepnpm run clean- Clean build artifacts
For testing releases before making them public:
-
Update the version in
package.jsonto a beta version:"version": "2.0.0-beta.0"
-
Publish to the beta tag:
pnpm run publish:beta
-
Test the beta version:
npm install @codex-data/sdk@beta
Users installing without the @beta tag will continue to receive the latest stable version.
-
Update the version in
package.jsonto a production version:"version": "2.0.0"
-
Publish to the latest tag:
pnpm run publish:latest
Note: The
prepublishOnlyscript automatically runs the full build before publishing, ensuring the package is always built before release.