SDK Initialization

Configure and initialize the Ferra DLMM SDK for your application.

Basic Setup

import { FerraDlmmSDK } from '@ferra-labs/dlmm'

const sdk = new FerraDlmmSDK({
  network: 'mainnet',
  fullNodeUrl: 'https://fullnode.mainnet.sui.io:443',
  senderAddress: '0x...' // Your wallet address
})

Configuration Options

Required Parameters

Parameter
Type
Description

network

'mainnet' | 'testnet'

Target network

fullNodeUrl

string

Sui RPC endpoint URL

senderAddress

string

Default sender for transactions

Network Configurations

Mainnet

const sdk = new FerraDlmmSDK({
  network: 'mainnet',
  fullNodeUrl: 'https://fullnode.mainnet.sui.io:443',
  senderAddress: '0x...'
})

Testnet

const sdk = new FerraDlmmSDK({
  network: 'testnet', 
  fullNodeUrl: 'https://fullnode.testnet.sui.io:443',
  senderAddress: '0x...'
})

Custom RPC

const sdk = new FerraDlmmSDK({
  network: 'mainnet',
  fullNodeUrl: 'https://your-custom-rpc.com',
  senderAddress: '0x...'
})

Wallet Integration

Set Sender Address

// Initialize without sender
const sdk = new FerraDlmmSDK({
  network: 'mainnet',
  fullNodeUrl: 'https://...'
})

// Set sender later
sdk.senderAddress = '0x123...'

// Update sender for different user
sdk.senderAddress = '0x456...'

With Wallet Adapter

import { useWallet } from '@mysten/wallet-adapter-react'

function App() {
  const { account } = useWallet()
  
  const sdk = useMemo(() => {
    return new FerraDlmmSDK({
      network: 'mainnet',
      fullNodeUrl: 'https://...',
      senderAddress: account?.address || ''
    })
  }, [account])
}

Module Access

After initialization, access SDK modules:

const sdk = new FerraDlmmSDK(config)

// Factory module - create pairs
const factory = sdk.Factory

// Pair module - interact with pairs
const pair = sdk.Pair

// Position module - manage positions
const position = sdk.Position

// SUI client - direct RPC access
const client = sdk.fullClient

Advanced Configuration

With Custom Package IDs

const sdk = new FerraDlmmSDK({
  network: 'mainnet',
  fullNodeUrl: 'https://...',
  senderAddress: '0x...',
  sdkOptions: {
    dlmm_pool: {
      package_id: '0x...', // Custom package ID
      config: {
        global_config: '0x...',
        pairs_id: '0x...'
      }
    }
  }
})

Connection Test

async function testConnection() {
  try {
    const sdk = new FerraDlmmSDK(config)
    
    // Test RPC connection
    const chainId = await sdk.fullClient.getChainIdentifier()
    console.log('Connected to:', chainId)
    
    // Test package access
    const pairs = await sdk.Pair.getPairs()
    console.log('Found pairs:', pairs.length)
    
  } catch (error) {
    console.error('Connection failed:', error)
  }
}

Environment Variables

Recommended setup using environment variables:

// .env file
VITE_NETWORK=mainnet
VITE_RPC_URL=https://fullnode.mainnet.sui.io:443
VITE_SENDER_ADDRESS=0x...

// Initialize SDK
const sdk = new FerraDlmmSDK({
  network: process.env.VITE_NETWORK as 'mainnet' | 'testnet',
  fullNodeUrl: process.env.VITE_RPC_URL!,
  senderAddress: process.env.VITE_SENDER_ADDRESS!
})

Error Handling

try {
  const sdk = new FerraDlmmSDK({
    network: 'mainnet',
    fullNodeUrl: 'invalid-url',
    senderAddress: '0x...'
  })
} catch (error) {
  if (error.message.includes('Invalid RPC')) {
    console.error('Please check your RPC URL')
  }
}

Best Practices

  1. Single Instance: Create one SDK instance per app

  2. Error Handling: Always wrap initialization in try-catch

  3. Network Matching: Ensure wallet and SDK use same network

  4. RPC Selection: Use reliable RPC providers for production

  5. Address Validation: Validate sender address format

Next Steps

SDK initialized! Continue to:

Last updated