Swap / DEX·Cosmos
Injective
Injective is a Cosmos SDK Layer-1 purpose-built for finance, with a native on-chain Central Limit Order Book (CLOB) module shared by all dApps, sub-second block times, and IBC + Wormhole connectivity. The exchange module handles spot, perpetual, and binary-options markets with on-chain matching and settlement; CosmWasm and Injective EVM (since 2025) provide programmability.
- 01on-chain orderbook trading (spot, perps, binary options)
- 02shared-liquidity DEX frontends
- 03high-throughput Cosmos finance dApps
- 04CosmWasm contracts that interact with the exchange module
- 05EVM finance apps with native orderbook access
- pnpm add @injectivelabs/sdk-ts @injectivelabs/networks @injectivelabs/wallet-ts
| Variable | Scope | Description |
|---|---|---|
| INJECTIVE_NETWORK | Client | Network selector: `mainnet`, `testnet`, or `devnet`. Used by `@injectivelabs/networks` to resolve RPC/LCD/gRPC-web/indexer endpoints. |
| INJECTIVE_RPC_URL | Client | Optional override for the Tendermint RPC URL (e.g., `https://sentry.tm.injective.network`). Only set if you don't use the bundled network presets. |
Use `@injectivelabs/sdk-ts`. Resolve endpoints with `getNetworkEndpoints(Network.Mainnet)` from `@injectivelabs/networks`. Read markets via `new IndexerGrpcSpotApi(endpoints.indexer).fetchMarkets()` and order book with `fetchOrderbookV2(marketId)`. To place a spot limit order, build with `MsgCreateSpotLimitOrder.fromJSON({ marketId, subaccountId, orderType: OrderType.Buy, price: spotPriceToChainPriceToFixed(...), quantity: spotQuantityToChainQuantityToFixed(...), feeRecipient, triggerPrice: '0' })` and broadcast with `MsgBroadcasterWithPk` or via a Keplr/Leap signer through `MsgBroadcaster`. CRITICAL: convert human prices/quantities to chain-format using the SDK helpers (`spotPriceToChainPriceToFixed`, `derivativePriceToChainPriceToFixed`) — the chain expects 18-decimal-scaled fixed-point values relative to base/quote decimals; a raw decimal will be interpreted as a microscopic order. Subaccounts (`<address>00000000000000000000000000000000000000000000000000000000`) hold trading balances separate from the main account; deposit via `MsgDeposit` from the bank module before placing orders.
- ⚑Price/quantity scaling is the #1 footgun: human-readable values must be converted via `*ToChainPriceToFixed`/`*ToChainQuantityToFixed` using the market's base and quote decimals. Skipping conversion produces orders 10^12+ off and either dust or instant rejection.
- ⚑Subaccounts vs. main accounts: trading happens against subaccount `0` (`<bech32>...0x00*32`) by default, but funds live on the main bank account until explicitly deposited via `MsgDeposit`. Forgetting this gives `insufficient funds` errors despite a non-zero wallet balance.
- ⚑CosmWasm version compatibility: Injective tracks specific cosmwasm-std versions per chain release; cw 1.5 → 2.0 cutover happened in a 2025 upgrade. Match contract version to chain version or instantiate fails.
- ⚑Chain upgrades: Injective ships frequent chain upgrades (3.x → 4.x → ... → 1.16 era for Cosmos SDK). After every upgrade, bump `@injectivelabs/sdk-ts` and `@injectivelabs/networks` to matching majors; old proto types break with `unknown message`.
- ⚑Slashing: 5% double-sign, 0.01% downtime; standard Cosmos params. Stakers should diversify validators and monitor uptime, especially during chain-upgrade windows when validators frequently miss blocks.
- ⚑IBC channel maintenance: Injective is heavily IBC-connected (Osmosis, Cosmos Hub, Noble). Light-client expiry (14-day trusting period) freezes IBC inflows of USDC, ATOM, OSMO, etc., until governance unfreezes. Monitor `client_states` if you depend on IBC liquidity.
- ⚑Gas token is `inj` (1 INJ = 10^18 inj — 18 decimals, unlike most Cosmos chains). Off-by-12 amount bugs are common; always use BigInt.
- ⚑Injective EVM (chainId `1776` mainnet) shares state with the Cosmos side via precompiles for the bank, exchange, and staking modules — Solidity contracts can read orderbook state directly, but precompile signatures change between chain upgrades. Pin precompile interface ABIs to the chain version.
- ⚑Trading fees: maker rebate / taker fee on spot/derivatives, denominated in quote asset. Fee parameters change via governance; never hard-code rates.