plugins/compact-core/skills/typescript-integration/SKILL.md
Use when implementing witness functions in TypeScript, mapping Compact types to TypeScript (Field→bigint, Bytes→Uint8Array), deploying contracts, calling circuits from TypeScript, reading ledger state, or building Midnight DApps with the JavaScript SDK.
npx skillsauth add aaronbassett/midnight-knowledgebase compact-core:typescript-integrationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
4 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Complete guide to integrating Midnight Compact contracts with TypeScript applications.
| Compact Type | TypeScript Type | Notes |
|--------------|-----------------|-------|
| Field | bigint | ZK field element |
| Uint<N> | bigint | Any bit width maps to bigint |
| Boolean | boolean | Direct mapping |
| Bytes<N> | Uint8Array | Fixed-length byte array |
| Opaque<'string'> | string | UTF-8 string data |
| Opaque<'Uint8Array'> | Uint8Array | Binary data |
| struct | { field: Type, ... } | Object with typed fields |
| enum | Discriminated union | { tag: 'Variant', value: T } |
| Vector<T, N> | T[] | Array of mapped type |
import { WitnessContext } from '@midnight-ntwrk/midnight-js-types';
// Compact declaration: witness get_secret(): Field;
const witnesses = {
get_secret: ({ privateState }: WitnessContext<PrivateState>): bigint => {
return privateState.secret;
}
};
1. Compile Compact → Generated TypeScript types
2. Deploy contract → Get contract address
3. Create provider → Connect to Midnight node
4. Build witnesses → Implement private data access
5. Call circuits → Execute transactions
6. Read state → Query ledger values
import { Contract } from './contract';
const result = await contract.callTx.transfer({
to: recipientAddress,
amount: 1000n
}, witnesses);
const balance = await contract.state.balances.get(userAddress);
// balance: bigint | undefined
import { deployContract } from '@midnight-ntwrk/midnight-js-contracts';
const { contract, address } = await deployContract(provider, {
privateStateKey: 'my-contract',
initialPrivateState: { secret: 42n },
witnesses
});
For detailed documentation on each topic:
Working TypeScript examples:
tools
Use when setting up Midnight development environment, installing Compact compiler and developer tools, configuring proof server, verifying prerequisites, or getting started with Midnight development.
tools
--- name: midnight-tooling:midnight-debugging description: Use when encountering Midnight errors like "compact: command not found", "ERR_UNSUPPORTED_DIR_IMPORT", version mismatches, proof server failures, "@midnight-ntwrk" package errors, or compilation failures. --- # Midnight Environment Debugging Expert knowledge for identifying and resolving common Midnight development toolchain issues. ## Diagnostic Approach When encountering Midnight-related errors, follow this systematic approach: 1.
tools
Use when checking Midnight version compatibility, understanding pragma language_version, verifying compiler and runtime version relationships, or troubleshooting version mismatch errors between Midnight components.
tools
Use when setting up CI/CD for Midnight projects, configuring GitHub Actions for Compact contract compilation, running TypeScript tests in CI, validating version consistency, or automating contract builds.