Sui.

Post

Share your knowledge.

article banner.
fomo on Sui.
Jul 08, 2025
Article

How to swap token using 7k SDK

In this guide, I will walk you through how to install and use the @7kprotocol/sdk-ts


Installation

To get started, first install the SDK along with its required dependencies.

  1. Install the SDK:

    Run the following command to install the @7kprotocol/sdk-ts package:

    npm i @7kprotocol/sdk-ts
    
  2. Install Peer Dependency:

    The SDK requires @pythnetwork/pyth-sui-js as a peer dependency. If you don't have it installed yet, run the following command:

    npm i @pythnetwork/pyth-sui-js
    

Set Sui Client

To connect with the Sui blockchain, you need to set the Sui client. This can be done as follows:

import { SuiClient, getFullnodeUrl } from "@mysten/sui/client";
import { Config } from "@7kprotocol/sdk-ts";

const network = "mainnet"; // Use "mainnet" for production
const suiClient = new SuiClient({ url: getFullnodeUrl(network) });
Config.setSuiClient(suiClient);
console.log("Sui client", Config.getSuiClient());

Note: This SDK currently only supports mainnet.


Performing Transactions

One of the core features of this SDK is the ability to swap tokens and execute transactions. Let’s walk through two key operations:

1. Get Quote for Swap

To get a quote for a token swap, use the getQuote function. This will give you the details of the swap, such as the amount you can receive and the best possible route.

Example:

import { getQuote } from "@7kprotocol/sdk-ts";

const quoteResponse = await getQuote({
  tokenIn: "0x2::sui::SUI", // Token you're swapping from
  tokenOut: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC", // Token you're swapping to
  amountIn: "1000000000", // Amount you're swapping (in smallest unit)
});

You can also specify a list of DEXs from which to pull quotes. If not specified, the SDK will use the latest supported sources.

const quoteResponse = await getQuote({
  tokenIn: "0x2::sui::SUI",
  tokenOut: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
  amountIn: "1000000000",
  sources: [
    "suiswap",
    "turbos",
    "cetus",
    "bluemove",
    "kriya",
    "kriya_v3",
    "aftermath",
    "flowx",
  ], // Optional: list of supported sources
});

2. Build Transaction

Once you have the quote, the next step is to build a transaction. You can use the buildTx function to create the transaction with necessary details like slippage and commission.

import { buildTx } from "@7kprotocol/sdk-ts";

const result = await buildTx({
  quoteResponse,
  accountAddress: "0xSenderAddress", // Your wallet address
  slippage: 0.01, // 1% slippage tolerance
  commission: {
    partner: "<address to receive fee>", // Partner address for commission
    commissionBps: 0, // Commission rate in basis points (0 means no fee)
  },
});

const { tx, coinOut } = result || {};

Note: Even if commissionBps is set to 0, you still need to provide a partner address for tracking and analytics.


Full Example

Here’s a full example that puts it all together:

import { SuiClient, getFullnodeUrl } from "@mysten/sui/client";
import { getQuote, buildTx, executeTx, BluefinXTx } from "@7kprotocol/sdk-ts";
import { useSignTransaction } from "@mysten/wallet-kit";

// Initialize Sui Client
const network = "mainnet";
const suiClient = new SuiClient({ url: getFullnodeUrl(network) });
Config.setSuiClient(suiClient);

// Get Quote
const quoteResponse = await getQuote({
  tokenIn: "0x2::sui::SUI",
  tokenOut: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
  amountIn: "1000000000",
  sources: ["bluefinx"],
});

// Build Transaction
const { tx } = await buildTx({
  quoteResponse,
  accountAddress: "0xSenderAddress",
  slippage: 0.01,
  commission: {
    partner: "<address to receive fee>",
    commissionBps: 0,
  },
});

// Sign Transaction
const { mutateAsync: signTransaction } = useSignTransaction();
const { signature, bytes } = await signTransaction({
  transaction: tx instanceof BluefinXTx ? tx.txBytes : tx,
});

// Execute Transaction
const res = await executeTx(tx, signature, bytes);
console.log(res);

  • Sui
  • SDKs and Developer Tools
1
Share
Comments
.