Client

The ThetanutsClient is the single entry point to the Thetanuts SDK — it initializes all modules, manages provider/signer connections, and exposes chain configuration.

Constructor

import { ThetanutsClient } from '@thetanuts-finance/thetanuts-client';

const client = new ThetanutsClient({
  chainId: 8453,              // Required: Chain ID (Base = 8453)
  provider?: Provider,        // Optional: ethers.js provider
  signer?: Signer,            // Optional: For write operations
  referrer?: string,          // Optional: Referrer address for fees
  apiBaseUrl?: string,        // Optional: Override API URL
  indexerApiUrl?: string,     // Optional: Override indexer URL
  pricingApiUrl?: string,     // Optional: Override pricing URL
  wsUrl?: string,             // Optional: Override WebSocket URL
  env?: 'dev' | 'prod',       // Optional: Environment (default: prod)
  logger?: ThetanutsLogger,   // Optional: Custom logger
  keyStorageProvider?: KeyStorageProvider,  // Optional: Custom RFQ key storage
  rfqKeyPrefix?: string,      // Optional: Custom RFQ key prefix
});

Properties

Property
Type
Description

chainId

number

Active chain ID (e.g. 8453)

chainConfig

ChainConfig

Chain configuration with addresses and tokens

provider

Provider

ethers.js provider instance

signer

Signer | undefined

Signer for transactions

referrer

string | undefined

Default referrer address

apiBaseUrl

string

Orders API endpoint URL

indexerApiUrl

string

Indexer API endpoint URL

pricingApiUrl

string

Pricing API endpoint URL

stateApiUrl

string

RFQ state indexer URL

Modules Access

All SDK modules are accessed as properties on the client instance:

Chain Config Access

Helper Methods

getSignerAddress()

Get the address of the current signer. Throws SIGNER_REQUIRED if no signer is configured.

requireSigner()

Get the signer instance, throwing SIGNER_REQUIRED if unavailable.

Initialization Patterns

Read-only (no signer)

With signer (for transactions)

Browser with MetaMask

Custom logger

URL overrides

Error Handling

The client throws ThetanutsError for typed error conditions:

Architecture


See Also

Last updated