SDK
We have open-sourced the SDK for the swap functionality in Mimo V3.
Installation
bash
npm install @dappworks/mimoswap-sdkTrade API
REST API
Make a POST request to get a trade quote:
bash
curl 'https://swap-api.mimo.exchange/api/trade' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Content-Type: application/json' \
--data-raw '{
"chainId": 4689,
"protocols": "v2,v3,mixed",
"token0": {"address":"IOTX","decimals":18},
"token1": {"address":"0x97e6c48867fdc3918dfe9d169ecd005d1d90283","decimals":18},
"recipient":"0x7890256910829ECc1CDD50AB50B1E92EC90A28da",
"amount":"10000000000000000000",
"slippage":{"numerator":50,"denominator":10000},
"tradeType":"EXACT_INPUT"
}'Parameters
| Parameter | Description |
|---|---|
chainId | The ID of the blockchain network (e.g., 4689 for IoTeX) |
protocols | Comma-separated list of supported protocols. Valid options: v2, v3, mixed |
token0 | Details of the first token (address and decimals) |
token1 | Details of the second token (address and decimals) |
recipient | The wallet address that will receive the output token |
amount | The amount of the input token to exchange (as string) |
slippage | Allowed slippage tolerance (numerator/denominator) |
tradeType | Typically "EXACT_INPUT" or "EXACT_OUTPUT" |
SDK Usage
typescript
import { parseUnits } from 'viem';
import {
ChainId,
Token,
CurrencyAmount,
TradeType,
Percent,
} from '@dappworks/mimoswap-sdk/sdk-core';
import { JsonRpcProvider } from '@ethersproject/providers';
import {
AlphaRouter,
ID_TO_CHAIN_ID,
ID_TO_PROVIDER,
SwapType,
} from '@dappworks/mimoswap-sdk';
// Setup
const chainId = ID_TO_CHAIN_ID(ChainId.IOTEX);
const chainProvider = ID_TO_PROVIDER(chainId);
const provider = new JsonRpcProvider(chainProvider, chainId);
// Create tokens
const tokenIn = new Token(chainId, '0xa7108637552cec7e8c2dd08a9cd995caff8b4280', 18);
const tokenOut = new Token(chainId, '0x61db9b084326d2251ccb0252c18fd9b0e887ca4f', 18);
// Create router
const router = new AlphaRouter({ chainId, provider });
// Get route
const route = await router.route(
CurrencyAmount.fromRawAmount(tokenIn, parseUnits('1', 6).toString()),
tokenOut,
TradeType.EXACT_INPUT,
{
recipient: '0x0000000000000000000000000000000000000000',
slippageTolerance: new Percent(1000, 10_000),
type: SwapType.UNIVERSAL_ROUTER,
},
{
protocols: [Protocol.MIXED],
}
);
console.log('route =>', route);Repositories
- mimo-api: https://github.com/mimoprotocol/mimo-api
- mimoswap-sdk: https://github.com/mimoprotocol/mimoswap-sdk
For input/output parameters, refer to the Uniswap SDK documentation.