> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tokenlayer.network/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript SDK

> Typed client for Token Layer action and info flows

The `@token-layer/sdk-typescript` package wraps `POST /token-layer` and `POST /info` with typed request builders, auth helpers, and generated OpenAPI types.

## Install

```bash theme={null}
npm install @token-layer/sdk-typescript viem
```

## Quick start

```ts theme={null}
import { TokenLayer } from "@token-layer/sdk-typescript";

const tokenLayer = new TokenLayer({
  baseUrl: "https://api.tokenlayer.network/functions/v1",
  source: "Mainnet",
  auth: {
    type: "jwt",
    token: process.env.TL_JWT!,
  },
});

const result = await tokenLayer.info.getTokensV2({
  keyword: "base",
  limit: 20,
  offset: 0,
  order_by: "volume_24h",
  order_direction: "DESC",
});

console.log(result.success);
```

## Authentication modes

* `jwt`: server-side automation with a bearer token
* `apiKey`: direct API key authentication
* `wallet`: EIP-712 signing flows for wallet-authenticated actions such as `register` and signed `createToken`

## Wallet auth example

```ts theme={null}
import { TokenLayer } from "@token-layer/sdk-typescript";
import { createWalletClient, custom } from "viem";

const walletClient = createWalletClient({
  chain: undefined,
  transport: custom(window.ethereum),
});

const tokenLayer = new TokenLayer({
  baseUrl: "https://api.tokenlayer.network/functions/v1",
  source: "Mainnet",
  auth: {
    type: "wallet",
    walletClient,
    signatureChainId: "0x1",
  },
});

await tokenLayer.action.register();
```

## Common methods

### Actions

* `action.register(params?)`
* `action.createToken(params)`
* `action.tradeToken(params)`
* `action.sendTransaction(params)`
* `action.transferToken(params)`
* `action.claimRewards(params)`
* `action.createReferralCode(params)`
* `action.enterReferralCode(params)`
* `action.mintUsd(params)` for testnet flows

### Info

* `info.getTokensV2(params)`
* `info.quoteToken(params)`
* `info.me(params?)`
* `info.getPoolData(params)`
* `info.getUserBalance(params)`
* `info.searchToken(params)`
* `info.checkTokenOwnership(params)`
* `info.getUserFees(params?)`
* `info.getUserFeeHistory(params?)`
* `info.getLeaderboard(params?)`
* `info.getUserPortfolio(params?)`

## Builder defaults

Set builder attribution once and let the SDK inject it when the per-call payload does not provide one:

```ts theme={null}
const tokenLayer = new TokenLayer({
  baseUrl: "https://api.tokenlayer.network/functions/v1",
  defaults: {
    builder: {
      code: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
      fee: 50,
    },
  },
});
```

This affects:

* `action.createToken`
* `info.getTokensV2`

Explicit per-call values still win.

## Auth switching

If you need the same client configuration with different auth contexts:

```ts theme={null}
const base = new TokenLayer({
  baseUrl: "https://api.tokenlayer.network/functions/v1",
});

const walletTl = base.asWallet(walletClient, { signatureChainId: "0x1" });
const jwtTl = base.asJwt(process.env.TL_JWT!);
const apiKeyTl = base.asApiKey(process.env.TL_API_KEY!);
```

## Error handling

Requests throw `TokenLayerApiError` with:

* `status`
* `code`
* `message`
* `details`

## Local development in this repo

```bash theme={null}
cd packages/sdk-typescript
npm install
npm run generate:openapi-types
npm run build
```

The generated types come from the repo-wide OpenAPI spec published in this docs site.

## Examples

Example scripts live in `packages/sdk-typescript/examples` for:

* token creation
* trading
* transfers
* referral actions
* token search and pool reads
* fee, leaderboard, and portfolio reads
