createPublicClient
Factory that builds a read-only client extended with every query action.
Setup
import { createPublicClient, createTransport, testnet } from "@left-curve/sdk"
const client = createPublicClient({
chain: testnet,
transport: createTransport(),
})createPublicClient returns a PublicClient = Client<undefined, PublicActions>. The signer slot is undefined, so the type system forbids calling any signing action.
Configuration
chain — Chain. Chain config (id, name, URL, native coin). Use local, devnet, testnet, or mainnet from @left-curve/sdk.
transport — Transport. GraphQL transport instance from createTransport(url?, config?).
name — string, optional, default: "Public Client". Free-form label for debugging.
Methods
App
| Method | Description |
|---|---|
getAppConfig | App-level config (cached) |
getBalance | Balance of one denom for an address |
getBalances | Paginated Coins map for an address |
getSupply | Total supply of a single token |
getSupplies | Paginated map of token supplies |
getCode | Fetch a stored Wasm code by hash |
getCodes | Paginated list of stored codes |
getContractInfo | Contract metadata by address |
getContractsInfo | Paginated contract metadata |
queryWasmRaw | Raw base64 storage value |
queryWasmSmart | Typed JSON query against a contract |
queryApp | Generic typed query against the app |
queryStatus | Chain id and latest block info |
queryTx | Indexed transaction by hash |
simulate | Gas-simulate an unsigned tx |
Account Factory
| Method | Description |
|---|---|
forgotUsername | Users associated with a key hash |
getAccountInfo | Account details for an address |
getAccountSeenNonces | Most-recent nonces consumed by account |
getAccountStatus | Current UserStatus for an address |
getAllAccountInfo | Paginated map of all accounts |
getCodeHash | Current account contract code hash |
getNextAccountIndex | Next account index for a username |
getUser | User by index or name |
getUserKeys | Indexer-backed list of PublicKey |
DEX
| Method | Description |
|---|---|
dexStatus | Whether the DEX is paused |
getOrder | Details of a single active order |
getPair | Parameters of a single base/quote pair |
getPairs | Paginated list of trading pairs |
getPairStats | 24h stats for one pair |
getAllPairStats | 24h stats for every pair |
ordersByUser | Active orders for a user |
queryCandles | Paginated candles |
queryTrades | Paginated trades |
simulateSwapExactAmountIn | Quote output for an exact-input swap |
simulateSwapExactAmountOut | Quote input for an exact-output swap |
simulateWithdrawLiquidity | Coins returned for burning LP |
Perps
| Method | Description |
|---|---|
getPerpsUserState | PerpsUserState for a user |
getPerpsUserStateExtended | Extended state with PnL/equity/liq flags |
getPerpsOrdersByUser | Active perps orders for a user |
getPerpsLiquidityDepth | Bid/ask depth buckets for a pair |
getPerpsPairParam | PerpsPairParam for one pair |
getPerpsPairParams | Map of params across pairs |
getPerpsParam | Global perps parameters |
getPerpsPairStats | Indexer 24h stats for a perps pair |
getAllPerpsPairStats | Indexer 24h stats for every perps pair |
getPerpsPairState | PerpsPairState (OI, funding) for a pair |
getPerpsState | Global runtime state |
getPerpsVaultState | Perps vault state |
getVaultSnapshots | Historical vault snapshots |
getFeeRateOverride | Per-user fee rate override |
queryPerpsCandles | Paginated perps candles |
queryPerpsEvents | Paginated perps events |
Oracle
| Method | Description |
|---|---|
getPrices | Paginated Record<Denom, Price> from oracle |
Indexer
| Method | Description |
|---|---|
queryBlock | Block (by height or latest) |
searchTxs | Paginated transaction search |
accountSubscription | Account creation events |
blockSubscription | New finalized blocks |
candlesSubscription | Live candles for a pair |
eventsSubscription | Filtered live events |
eventsByAddressesSubscription | Live events for a set of addresses |
transferSubscription | Live transfer events for a username |
tradesSubscription | Live spot trades for a pair |
perpsCandlesSubscription | Live perps candles |
perpsTradesSubscription | Live perps trades |
queryAppSubscription | Live result of a queryApp request |
allPairStatsSubscription | Live 24h stats for all spot pairs |
allPerpsPairStatsSubscription | Live 24h stats for all perps pairs |
End-to-end example
import { createPublicClient, createTransport, testnet } from "@left-curve/sdk"
import type { Address } from "@left-curve/sdk"
const client = createPublicClient({
chain: testnet,
transport: createTransport(),
})
const status = await client.queryStatus()
const address: Address = "0x1234567890abcdef1234567890abcdef12345678"
const balances = await client.getBalances({ address })
const pairs = await client.getPairs({ limit: 10 })
const unsubscribe = client.blockSubscription({
next: ({ block }) => console.log("block", block.blockHeight),
})
// later
unsubscribe()Notes
- The client is a plain object, not a class. Method calls are just property reads followed by function calls.
- For tree-shakable usage, import each action and pass the client positionally:
getBalance(client, {...}).
See also
- createSignerClient — when you also need to broadcast
- createBaseClient — for custom action extension
- Concepts: Clients