ThetanutsClient

The main client class for interacting with Thetanuts Finance.

Overview

ThetanutsClient is the entry point to the SDK. It:

  • Initializes all feature modules

  • Manages provider and signer connections

  • Provides access to chain configuration

  • Handles HTTP client for API calls

Initialization

Read-Only Mode (No Signer)

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

const provider = new ethers.JsonRpcProvider('https://mainnet.base.org');

const client = new ThetanutsClient({
  chainId: 8453,
  provider,
});

// Read-only operations work
const orders = await client.api.fetchOrders();
const balance = await client.erc20.getBalance(tokenAddress, userAddress);

With Signer (For Transactions)

Browser with MetaMask

Configuration Options

Client Properties

chainId

chainConfig

Access chain configuration including contract addresses and tokens.

provider

The ethers.js provider instance.

apiBaseUrl, indexerApiUrl, pricingApiUrl, stateApiUrl

API endpoint URLs.

Modules

All modules are accessed as properties on the client:

Module
Property
Purpose

ERC20

client.erc20

Token operations

OptionBook

client.optionBook

Order filling/cancellation

API

client.api

Data fetching

OptionFactory

client.optionFactory

RFQ lifecycle

Option

client.option

Position management

Events

client.events

Blockchain events

WebSocket

client.ws

Real-time subscriptions

Pricing

client.pricing

Option pricing

Utils

client.utils

Decimal conversions

RFQKeyManager

client.rfqKeys

ECDH keys & encryption for RFQ

See modules/README.md for detailed documentation.

Helper Methods

getSignerAddress()

Get the address of the current signer.

requireSigner()

Get the signer, throwing if not available.

Custom Logger

Pass a custom logger for debugging:

URL Overrides

Override API URLs for development or testing:

Example: Complete Setup

Error Handling

The client throws ThetanutsError for various conditions:

Last updated