npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@token-layer/sdk-typescript

v0.1.23

Published

TypeScript SDK for Token Layer /token-layer endpoint

Readme

@token-layer/sdk-typescript

TypeScript SDK for POST /token-layer and POST /info.

Also includes a beta WebSocket helper for tokenActivity streams.

Install

npm install @token-layer/sdk-typescript viem

Quick start (wallet auth)

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",
  defaults: {
    builder: {
      code: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
      fee: 50,
    },
  },
  auth: {
    type: "wallet",
    walletClient,
    signatureChainId: "0x1",
  },
});

await tokenLayer.action.register();

const action = tokenLayer.prepare.createToken({
  name: "My Cool Token",
  symbol: "MCT",
  description: "A new token",
  image: "https://example.com/logo.png",
  chainSlug: "base",
});

const createResponse = await tokenLayer.action.createToken({
  action,
});

console.log(createResponse.success);

JWT/API key auth

import { TokenLayer } from "@token-layer/sdk-typescript";

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

await tokenLayerJwt.action.createToken({
  action: tokenLayerJwt.prepare.createToken({
    name: "My Cool Token",
    symbol: "MCT",
    description: "A new token",
    image: "https://example.com/logo.png",
    chainSlug: "base",
  }),
});

Auth switching helpers

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

const walletTl = base.asWallet(walletClient, { signatureChainId: "0x1" });
const jwtTl = base.asJwt(jwt);
const apiKeyTl = base.asApiKey(apiKey);

API

  • action.register(params?) (wallet auth only)
  • action.createToken(params)
  • action.tradeToken(params) (JWT/API key auth)
  • action.sendTransaction(params) (JWT/API key auth)
  • action.transferToken(params) (JWT/API key auth)
  • action.claimRewards(params) (JWT/API key auth)
  • action.createReferralCode(params) (JWT/API key auth)
  • action.enterReferralCode(params) (JWT/API key auth)
  • action.mintUsd(params) (JWT/API key auth, testnet-only action)
  • prepare.createToken(actionDraft) (local typed helper)
  • info.getTokensV2(params) (no auth required)
  • info.quoteToken(params) (no auth required)
  • info.me(params?) (JWT/API key auth)
  • info.getPoolData(params) (no auth required)
  • info.getUserBalance(params) (JWT/API key auth)
  • info.searchToken(params) (no auth required)
  • info.checkTokenOwnership(params) (no auth required)
  • info.getUserFees(params?) (JWT/API key auth)
  • info.getUserFeeHistory(params?) (JWT/API key auth)
  • info.getLeaderboard(params?) (no auth required)
  • info.getUserPortfolio(params?) (JWT/API key auth)
  • websocket(options?)
  • asWallet(walletClient, opts?)
  • asJwt(token)
  • asApiKey(token)
  • signRegisterRequest(walletClient, params)
  • signCreateTokenRequest(walletClient, params)
  • buildRegisterMessage(address, nonceMs)

Client defaults

Set builder defaults once on client init:

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

Merge behavior:

  • action.createToken: if action.builder is missing, SDK injects defaults { code, fee }.
  • info.getTokensV2: if builder_code is missing, SDK injects default builder.code.
  • Explicit per-call values always win over defaults.
  • If defaults.builder.fee is omitted, SDK uses 0.

Info endpoint

import { TokenLayer } from "@token-layer/sdk-typescript";

const tokenLayer = new TokenLayer({
  baseUrl: "https://api.tokenlayer.network/functions/v1",
});

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

const quote = await tokenLayer.info.quoteToken({
  chainSlug: "base",
  tokenId: "550e8400-e29b-41d4-a716-446655440000",
  direction: "buy",
  inputToken: "usdc",
  amount: 10,
});

const leaderboard = await tokenLayer.info.getLeaderboard({
  limit: 10,
  offset: 0,
  network_mode: "both",
});

New Action Examples

const authed = tokenLayer.asJwt(process.env.JWT!);

await authed.action.tradeToken({
  action: {
    tokenId: "550e8400-e29b-41d4-a716-446655440000",
    chainSlug: "base",
    direction: "buy",
    buyAmountUSD: 5,
  },
});

await authed.action.sendTransaction({
  action: {
    to: "0x000000000000000000000000000000000000dEaD",
    amount: "1",
    chainSlug: "base",
  },
});

Errors

Requests throw TokenLayerApiError with:

  • status
  • code
  • details
  • message

WebSocket beta

import { TokenLayer } from "@token-layer/sdk-typescript";

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

const ws = tokenLayer.websocket({
  url: "ws://127.0.0.1:8080/ws",
});

await ws.connect();

await ws.subscribeTokenActivity({
  tokenIds: ["your-token-layer-id"],
  chains: ["base-sepolia"],
  activityTypes: ["trade"],
  activitySubtypes: ["buy", "sell"],
  cursor: "latest",
  onEvent(event) {
    console.log(event.seq, event.data.activity_type);
  },
});

Current WebSocket helper support:

  • auth via API key or JWT
  • tokenActivity subscription
  • walletBalances subscription
  • walletFees subscription
  • optional filters for tokenIds, chains, activityTypes, and activitySubtypes
  • optional wallet balance filters for wallet, wallets, tokenId, tokenIds, and chains
  • optional wallet fee filters for wallet, wallets, currency, currencies, activityIds, distributionTypes, and chains
  • event-stream cursors via cursor, sinceTimestamp, and batchSize
  • automatic reconnect and resubscribe with resume from the last seen seq

Wallet-authenticated websocket sessions are not implemented yet.