Getting Started
Get started with Moromoro SDK in minutes! This guide will walk you through making your first swap on HyperEVM.
Basic Setup
2
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
Method 1: Using SDK Helper (Recommended)
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
API Reference - Full API documentation
Examples - More code examples
HyperEVM Contracts - Contract addresses and details
Split Trading - Learn about split trades
Common Issues
Getting Help
https://github.com/moromoro/moro-sdk/issues
https://discord.gg/moromoro