Skip to main content

Installation

The SDK has zero runtime dependencies. viem is a peer dependency for type compatibility but is not imported by the SDK itself. You need viem (or ethers) separately to interact with the chain.

What the SDK Exports

ABIs

Typed ABI arrays for every protocol contract, ready to use with viem or wagmi:

Constants

Enums and identifiers that match onchain values:
The bundled PAIRS and TENORS caches are sourced from the canonical defaults file and travel with each SDK release. For authoritative state at runtime, prefer the on-chain getters (OracleModule.getAllPairs() and Config.getEnabledTenors()) — they always reflect the live registry.

Labels

Pair-agnostic labels ship from the SDK; pair-aware side labels (e.g. "Long EUR" vs "Short USD") come from @nile-markets/shared. Side labels derive from the pair’s base currency — Pyth-native ordering, so USD/JPY"Long USD", not "Long JPY".

Setting Up a Client

Create a viem public client to read contract state. For write operations, you also need a wallet client.
See Contract Addresses for all deployed addresses on Sepolia.

Reading Contract State

Pool State

Query the PoolVault for total deposits and share supply:

Forward Prices

Read the current EUR/USD forward price for a specific tenor. getForwardByTenor resolves the next fixing timestamp for that tenor automatically:

Protocol Mode

Check the current operating mode before submitting transactions:

Margin Account Balance

Read a trader’s deposited collateral and available balance:

Writing Transactions

Approve USDC and Open a Position

Opening a position requires two transactions: approve USDC spending, then call openPosition.

Deposit Margin

Deposit USDC collateral into your MarginAccounts balance:

Numeric Precision

All onchain values use fixed-point integers. You need to convert between human-readable numbers and raw contract values. Use viem’s parseUnits and formatUnits for conversion:
Never use floating-point arithmetic with contract values. Always operate on bigint values and convert to human-readable strings only for display.

Using with wagmi

If you are building a React frontend with wagmi, the SDK ABIs work directly with wagmi hooks:

Contract Addresses

Sepolia deployment addresses for all contracts.

Types Reference

Full enum and struct definitions used across the protocol.

Quick Start

End-to-end setup from zero to querying protocol state.

Open a Position

Step-by-step tutorial for your first trade.