Skip to main content

Installation

You can install the SDK using npm from the GitHub repository:
npm i github:bison-markets/sdk-ts

Basic Usage

To avoid ambiguity, we denote the smallest possible multiple of USDC (0.000001 USDC) as one uusdc, which stands for µUSDC (micro-USDC).
example.ts
import { createBisonClient } from '@bison-markets/sdk-ts';
import { createWalletClient, createPublicClient, http, custom } from 'viem';
import { base } from 'viem/chains';

// Create a client instance
const client = createBisonClient({ 
  baseUrl: 'https://api.bison.markets' 
});

// Create a wallet client for signing transactions
const walletClient = createWalletClient({
  chain: base,
  transport: custom(window.ethereum!),
});

// Create a public client for reading blockchain state
const publicClient = createPublicClient({
  chain: base,
  transport: http(),
});

// Deposit 100 USDC
const txHash = await client.executeDepositFlow({
  walletClient,
  publicClient,
  userAddress: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  chain: 'base', // Addresses are auto-resolved and cached
  amountUusdc: 100_000_000, // 100 USDC
});

console.log('Deposited! Transaction:', txHash);

// Start listening for account events
const disconnect = client.listen(
  '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  (event) => {
    if (event.type === 'usdc_deposited') {
      console.log('USDC deposit confirmed:', event.uusdcAmount / 1_000_000, 'USDC');
    } else if (event.type === 'order_filled') {
      console.log('Order filled:', event.orderId);
    }
  }
);

// Clean up when done
// disconnect();

Configuration

The SDK requires only the base URL of the Bison API:
const client = createBisonClient({ 
  baseUrl: 'https://api.bison.markets' 
});

Developer Accounts

If you have a developer account, you can set it at the client level to automatically apply it to all orders:
const client = createBisonClient({ 
  baseUrl: 'https://api.bison.markets',
  devAccountId: 'your-dev-account-id'
});
All orders placed through this client will be associated with your dev account, allowing you to earn a portion of trading fees. See the Developer Accounts guide for more information on how to get a dev account and configure fee structures. You can find detailed usage information on the next few pages.