Mainly

TypeScript

Install and make your first Mainly request with the TypeScript SDK.

The official TypeScript SDK is published to npm as @mainly-live/sdk.

Install

pnpm add @mainly-live/sdk

You can also install it with npm install @mainly-live/sdk, yarn add @mainly-live/sdk, or bun add @mainly-live/sdk.

Make a request

Create one client and reuse it across requests:

import { Mainly } from "@mainly-live/sdk";

const token = process.env.MAINLY_API_KEY;
if (!token) throw new Error("MAINLY_API_KEY is not set");

const client = new Mainly({
  token,
});

const balance = await client.solana.wallets.getBalance({
  address: "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM",
});

console.log(`Balance: ${balance.sol} SOL`);

The token option sends your key as an Authorization: Bearer header. Keep this code on the server so the key is not included in a browser bundle.

Choose a network

Resources are grouped by chain and network on the client:

client.solana;
client.solanaDevnet;
client.ethereum;
client.ethereumSepolia;

For example, change client.solana to client.solanaDevnet to make the same request against Solana devnet.

Handle errors

Non-successful API responses throw MainlyError or one of its typed subclasses:

import { MainlyError } from "@mainly-live/sdk";

try {
  await client.solana.wallets.getBalance({ address: "invalid" });
} catch (error) {
  if (error instanceof MainlyError) {
    console.error(error.statusCode, error.message, error.body);
  }
}

The client retries retryable failures with exponential backoff. Use maxRetries and timeoutInSeconds on the client or an individual request to override the defaults.

Next, browse the API reference or see the complete TypeScript SDK source.

On this page