Getting Started

Get started with Moromoro SDK in minutes! This guide will walk you through making your first swap on HyperEVM.

Basic Setup

1

Install Dependencies

npm install @moromoro/moro-sdk ethers
2

Import the SDK

const { MoroBestRate } = require('@moromoro/moro-sdk')
const { ethers } = require('ethers')

For TypeScript/ES6:

import { MoroBestRate } from '@moromoro/moro-sdk'
import { ethers } from 'ethers'
3

Initialize Provider and Client

// Connect to HyperEVM
const provider = new ethers.providers.JsonRpcProvider('https://rpc.hyperliquid.xyz/evm')

// Create Moromoro client
const moroClient = new MoroBestRate(provider, 'hyperevm')

Getting a Quote

Simple Quote Example

// Token addresses
const HYPE = '0x5555555555555555555555555555555555555555' // Native token
const USDT = '0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb' // USDT0

// Swap parameters
const amountIn = ethers.utils.parseUnits('10', 18) // 10 HYPE
const gasFee = ethers.BigNumber.from('5000000000') // 5 gwei

// Get best rate quote
const quote = await moroClient.getQuote(
    HYPE,           // source token
    USDT,           // destination token
    amountIn,       // amount to swap
    gasFee,         // gas price for calculation
    { enableSplit: false } // options
)

console.log('Quote:', quote)
console.log('Amount Out:', ethers.utils.formatUnits(quote.amountOut, 6))

Quote Response

The quote object contains:

{
    amountOut: "15000000",        // Output amount in wei
    swapAddress: "0x...",         // DEX wrapper address
    data: "0x...",                // Encoded swap data
    depositAddress: "0x...",      // DEX deposit address
    type: "single",               // Quote type: 'single' or 'split'
    path: [...],                  // Trading path information
    // ... additional fields
}

Executing a Swap

const { MoroBestRate } = require('@moromoro/moro-sdk')
const { ethers } = require('ethers')

async function executeSwap() {
    // Setup
    const provider = new ethers.providers.JsonRpcProvider('https://rpc.hyperliquid.xyz/evm')
    const signer = new ethers.Wallet(YOUR_PRIVATE_KEY, provider)
    const moroClient = new MoroBestRate(provider, 'hyperevm')

    // Token addresses
    const HYPE = '0x5555555555555555555555555555555555555555'
    const USDT = '0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb'

    const amountIn = ethers.utils.parseUnits('10', 18)
    const gasFee = ethers.BigNumber.from('5000000000')

    // Get quote
    const quote = await moroClient.getQuote(HYPE, USDT, amountIn, gasFee)

    // Calculate minimum output with 1% slippage
    const minAmountOut = ethers.BigNumber.from(quote.amountOut).mul(99).div(100)

    // Execute swap
    const tx = await moroClient.swap(
        signer,
        HYPE,
        USDT,
        amountIn,
        minAmountOut,
        quote
    )

    console.log('Transaction hash:', tx.hash)

    // Wait for confirmation
    const receipt = await tx.wait()
    console.log('Swap confirmed in block:', receipt.blockNumber)
}

executeSwap()

Method 2: Direct Contract Interaction

const moroRouterAbi = require('./MoroRouter_2_0.abi.json')
const MORO_ROUTER = '0x3195cAd938d417703312246e376342C553FD4cC2'

async function executeSwapDirect() {
    const provider = new ethers.providers.JsonRpcProvider('https://rpc.hyperliquid.xyz/evm')
    const signer = new ethers.Wallet(YOUR_PRIVATE_KEY, provider)
    const moroClient = new MoroBestRate(provider, 'hyperevm')

    // Get quote
    const HYPE = '0x5555555555555555555555555555555555555555'
    const USDT = '0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb'
    const amountIn = ethers.utils.parseUnits('10', 18)
    const gasFee = ethers.BigNumber.from('5000000000')

    const quote = await moroClient.getQuote(HYPE, USDT, amountIn, gasFee)

    // Add slippage protection
    const minAmountOut = ethers.BigNumber.from(quote.amountOut).mul(99).div(100)

    // Create contract instance
    const moroContract = new ethers.Contract(MORO_ROUTER, moroRouterAbi, signer)

    // Execute swap
    const tx = await moroContract.swap(
        quote.swapAddress,
        quote.data,
        quote.depositAddress,
        HYPE,
        amountIn,
        USDT,
        minAmountOut,
        signer.address,  // receiver
        0,               // partnerId
        0,               // metadata
        { value: amountIn } // for native token swaps
    )

    await tx.wait()
    console.log('Swap completed:', tx.hash)
}

executeSwapDirect()

Swapping ERC20 Tokens

When swapping ERC20 tokens (non-native), you need to approve the router first:

async function swapERC20() {
    const provider = new ethers.providers.JsonRpcProvider('https://rpc.hyperliquid.xyz/evm')
    const signer = new ethers.Wallet(YOUR_PRIVATE_KEY, provider)
    const moroClient = new MoroBestRate(provider, 'hyperevm')

    const USDT = '0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb'
    const HYPE = '0x5555555555555555555555555555555555555555'
    const amountIn = ethers.utils.parseUnits('100', 6) // 100 USDT
    const gasFee = ethers.BigNumber.from('5000000000')

    // Get quote
    const quote = await moroClient.getQuote(USDT, HYPE, amountIn, gasFee)

    // Approve token spending
    const approveTx = await moroClient.approve(signer, USDT, amountIn)
    await approveTx.wait()
    console.log('Token approved')

    // Execute swap
    const minAmountOut = ethers.BigNumber.from(quote.amountOut).mul(99).div(100)
    const swapTx = await moroClient.swap(
        signer,
        USDT,
        HYPE,
        amountIn,
        minAmountOut,
        quote
    )

    await swapTx.wait()
    console.log('Swap completed:', swapTx.hash)
}

swapERC20()

Enable Split Trading

For potentially better rates, enable split trading:

const quote = await moroClient.getQuote(
    srcToken,
    destToken,
    amountIn,
    gasFee,
    { enableSplit: true } // Enable split trades
)

// Check if quote is split
if (quote.type === 'split') {
    console.log('Trade will be split across multiple DEXs')
    console.log('Paths:', quote.paths)
    console.log('Volumes:', quote.volumns)
}

Supported Networks

Initialize the SDK with different networks:

// HyperEVM
const hyperClient = new MoroBestRate(provider, 'hyperevm')

// BSC
const bscClient = new MoroBestRate(bscProvider, 'bsc')

// Ethereum
const ethClient = new MoroBestRate(ethProvider, 'ethereum')

// Polygon
const polygonClient = new MoroBestRate(polygonProvider, 'polygon')

// Arbitrum
const arbClient = new MoroBestRate(arbProvider, 'arbitrum')

// Avalanche
const avaxClient = new MoroBestRate(avaxProvider, 'avalanche')

// Optimism
const opClient = new MoroBestRate(opProvider, 'optimism')

Complete Example

Here's a complete example with error handling:

const { MoroBestRate } = require('@moromoro/moro-sdk')
const { ethers } = require('ethers')

async function main() {
    try {
        // Setup
        const provider = new ethers.providers.JsonRpcProvider(
            'https://rpc.hyperliquid.xyz/evm'
        )
        const signer = new ethers.Wallet(process.env.PRIVATE_KEY, provider)
        const moroClient = new MoroBestRate(provider, 'hyperevm')

        // Check balance
        const balance = await signer.getBalance()
        console.log('Balance:', ethers.utils.formatEther(balance), 'HYPE')

        // Define swap
        const HYPE = '0x5555555555555555555555555555555555555555'
        const USDT = '0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb'
        const amountIn = ethers.utils.parseUnits('10', 18)
        const gasFee = ethers.BigNumber.from('5000000000')

        // Get quote
        console.log('Getting best rate...')
        const quote = await moroClient.getQuote(HYPE, USDT, amountIn, gasFee, {
            enableSplit: true
        })

        console.log('Best rate found!')
        console.log('Output amount:', ethers.utils.formatUnits(quote.amountOut, 6), 'USDT')
        console.log('Type:', quote.type)

        // Calculate slippage
        const minAmountOut = ethers.BigNumber.from(quote.amountOut)
            .mul(99)
            .div(100)

        // Execute swap
        console.log('Executing swap...')
        const tx = await moroClient.swap(
            signer,
            HYPE,
            USDT,
            amountIn,
            minAmountOut,
            quote
        )

        console.log('Transaction submitted:', tx.hash)

        // Wait for confirmation
        const receipt = await tx.wait()
        console.log('✓ Swap confirmed in block', receipt.blockNumber)

    } catch (error) {
        console.error('Error:', error.message)
        process.exit(1)
    }
}

main()

Next Steps

Common Issues

Insufficient Balance
Error: insufficient funds for gas * price + value

Solution: Ensure your wallet has enough native tokens for the swap amount + gas fees.

Slippage Exceeded
Error: slippage exceeded

Solution: Increase slippage tolerance:

// Increase to 2% slippage
const minAmountOut = quote.amountOut.mul(98).div(100)
Token Not Approved
Error: ERC20: transfer amount exceeds allowance

Solution: Approve the token before swapping:

await moroClient.approve(signer, tokenAddress, amount)

Getting Help

  • https://github.com/moromoro/moro-sdk/issues

  • https://discord.gg/moromoro