Skip to content

Quick start

Get up and running with the TypeScript SDK

Installation

Install

First, we install kuru-sdk

npm
npm i @kuru-labs/kuru-sdk

Configure environment

Export your PRIVATE_KEY and the KURU_API to use the examples

Terminal
export PRIVATE_KEY=<your_private_key>
 
export KURU_API=<kuru_api_url>

Update config.json

config.json
{
    "rpcUrl": "monad_rpc_url",
    "marginAccountAddress": "0x38453021C50A2b76a8595e3a985f4f4195a3C954",
    "routerAddress": "0xc4b11B176D4194A0175709cac9fEf9DFD40C005A",
}

Deposit into margin account

import { ethers } from "ethers";
import * as KuruSdk from "../../src";
import * as KuruConfig from "../config.json";
 
const {rpcUrl, marginAccountAddress} = KuruConfig;
 
const privateKey = process.env.PRIVATE_KEY as string;
 
(async () => {
    const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
    const signer = new ethers.Wallet(privateKey, provider);
 
    try {   
        const receipt = await KuruSdk.MarginDeposit.deposit( 
            signer, 
            marginAccountAddress, 
            signer.address, // address you want to deposit funds for
            <token_address>, // token to deposit
            100000, // amount
            18, // decimals
            true // approve for erc-20 tokens (if not approved already)
        ); 
        console.log("Transaction hash:", receipt.transactionHash); // 
    } catch (error: any) { // 
        console.error("Error depositing:", error); // 
    }
})();

Place a limit buy

Placing a limit order. This consumes funds in your margin account

import { ethers } from "ethers";
import * as KuruSdk from "../../src";
import * as KuruConfig from "../config.json";
 
const { rpcUrl } = KuruConfig;
const marketAddress = <your_market_address>; // market address
 
const privateKey = process.env.PRIVATE_KEY as string;
 
const price = 135.50; // Price in quoteAsset (ex:USDC)
const size = 10; // Size in baseAsset (ex:MON)
 
(async () => {
    const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
    const signer = new ethers.Wallet(privateKey, provider);
 
    const marketParams = await KuruSdk.ParamFetcher.getMarketParams( 
        provider, 
        marketAddress
    );
 
    try { 
        const receipt = await KuruSdk.GTC.placeLimit(   
            signer,   
            marketAddress,   
            marketParams,   
            {   
                price,   
                size,   
                isBuy: true,   
                postOnly: true
            }   
        );   
        console.log("Transaction hash:", receipt.transactionHash);
    } catch (error) {
        console.error("Error placing limit buy order:", error);
    }
})();

Next steps

Now that you have a basic set up in place, read all the functionality of the SDK:

Order book
Router