Step-by-Step Tutorial

How to Integrate SUI Lab Factory into Your dApp

Complete tutorial for developers of all levels

🎯 Example Scenario

Imagine youre building a token launchpad called MyLaunchpad. You want that when a token graduates, a liquidity pool is automatically created on SUI Lab DEX.

Result: Your user launches a token → Reaches goal → BOOM! Pool automatically created on your DEX. Without building anything from scratch. 🚀

1

Install the SDK in Your Project

Open your terminal in your React/Next.js project and run:

npm install @suilab/factory-sdk @mysten/sui @mysten/dapp-kit
What did we install?
  • @suilab/factory-sdk - Our SDK
  • @mysten/sui - SUI Client
  • @mysten/dapp-kit - React hooks for SUI
2

Configure the SDK

Create a file src/lib/poolFactory.ts:

import { SuiLabFactorySDK } from '@suilab/factory-sdk';
import { SuiClient } from '@mysten/sui/client';

// Configure SUI client
const client = new SuiClient({ 
  url: 'https://fullnode.mainnet.sui.io:443' 
});

// Initialize SDK
export const factorySDK = new SuiLabFactorySDK(client, 'MAINNET');

// Export fee (3 SUI)
export const POOL_FEE = 3_000_000_000; // in MIST
3

Create Button Component

Create src/components/CreatePoolButton.tsx:

import { useSignAndExecuteTransaction } from '@mysten/dapp-kit';
import { factorySDK } from '@/lib/poolFactory';
import { parseSUI } from '@suilab/factory-sdk';

export function CreatePoolButton({ 
  tokenType,
  currentWalletAddress 
}: { 
  tokenType: string;
  currentWalletAddress: string;
}) {
  const { mutate: signAndExecute } = useSignAndExecuteTransaction();
  
  const handleCreatePool = async () => {
    try {
      // 1. Prepare parameters
      const poolParams = {
        tokenAType: '0x2::sui::SUI',      // SUI
        tokenBType: tokenType,             // Your token
        tokenAAmount: parseSUI(100),       // 100 SUI
        tokenBAmount: BigInt(1_000_000_000_000), // 1M tokens
        senderAddress: currentWalletAddress,
      };
      
      // 2. Create transaction (SDK handles fee automatically)
      const transaction = factorySDK.createPoolTransaction(poolParams);
      
      // 3. Sign and execute
      signAndExecute(
        { transaction },
        {
          onSuccess: (result) => {
            alert('Pool created successfully! ' + result.digest);
          },
          onError: (error) => {
            alert('Error: ' + error.message);
          }
        }
      );
      
    } catch (error) {
      console.error('Error:', error);
    }
  };
  
  return (
    <button 
      onClick={handleCreatePool}
      className="bg-blue-600 text-white px-6 py-3 rounded-lg hover:bg-blue-700"
    >
      Create Pool on SUI Lab DEX
    </button>
  );
}
4

Use the Component

On any page of your dApp:

import { CreatePoolButton } from '@/components/CreatePoolButton';
import { useCurrentAccount } from '@mysten/dapp-kit';

export function TokenPage() {
  const account = useCurrentAccount();
  
  return (
    <div>
      <h1>My DAO Token</h1>
      
      {account && (
        <CreatePoolButton 
          tokenType="0xABC123::mytoken::MYTOKEN"
          currentWalletAddress={account.address}
        />
      )}
    </div>
  );
}

Important: The 3 SUI Fee

What happens if I dont pay the fee?

The transaction will FAIL. The SUI Lab Factory smart contract requires exactly 3 SUI to create a pool. Its not optional.

Does the SDK handle this automatically?

Yes. When you use createPoolTransaction(), the SDK automatically splits 3 SUI from the users gas for the fee. You dont need to do anything extra.

// Internally the SDK does this: const [paymentCoin] = txb.splitCoins(txb.gas, [3_000_000_000]);

🎁 What You Get

Fast Development

Integration in minutes, not months

🔒

Proven Security

Audited and tested contracts

💰

No Hidden Costs

Only 3 SUI per pool created

📊

Complete Functions

Queries, calculations, all included

Ready to Get Started?

Explore more examples and complete documentation

Need help? Contact us at support@suilab.fun