Skip to main content
This guide will walk you through creating and executing your first Fusion Mode swap. You’ll learn how to set up the SDK, get a quote, and submit an order.

Prerequisites

Before you begin, ensure you have:
  • Node.js 16+ installed
  • A blockchain RPC provider URL (Alchemy, Infura, etc.)
  • A private key for signing transactions
  • A 1inch Dev Portal API token (get one here)
  • Some tokens to swap (for testing, use a testnet)
Never commit private keys to version control. Use environment variables or a secure secrets manager.

Step-by-step guide

1

Install the SDK

Install the 1inch Fusion SDK using your preferred package manager:
npm install @1inch/fusion-sdk
Also install ethers for blockchain interaction:
npm install ethers
2

Set up your environment

Create a .env file with your configuration:
PRIVATE_KEY=your_private_key_here
RPC_URL=your_rpc_url_here
API_TOKEN=your_1inch_api_token_here
Add .env to your .gitignore file to prevent accidentally committing sensitive data.
3

Initialize the SDK

Create a new file swap.ts and set up the SDK:
import { 
  FusionSDK, 
  NetworkEnum, 
  PrivateKeyProviderConnector,
  Web3Like 
} from '@1inch/fusion-sdk'
import { JsonRpcProvider, computeAddress } from 'ethers'

// Configuration
const PRIVATE_KEY = process.env.PRIVATE_KEY!
const RPC_URL = process.env.RPC_URL!
const API_TOKEN = process.env.API_TOKEN!

// Set up the blockchain provider
const ethersProvider = new JsonRpcProvider(RPC_URL)

const web3Provider: Web3Like = {
  eth: {
    call(transactionConfig): Promise<string> {
      return ethersProvider.call(transactionConfig)
    }
  },
  extend(): void {}
}

// Create the blockchain connector
const connector = new PrivateKeyProviderConnector(
  PRIVATE_KEY,
  web3Provider
)

// Initialize the SDK
const sdk = new FusionSDK({
  url: 'https://api.1inch.dev/fusion',
  network: NetworkEnum.ETHEREUM,
  blockchainProvider: connector,
  authKey: API_TOKEN
})

console.log('SDK initialized successfully')
4

Get a quote

Get a quote for your desired swap:
async function getSwapQuote() {
  const walletAddress = computeAddress(PRIVATE_KEY)

  const params = {
    fromTokenAddress: '0x6b175474e89094c44da98b954eedeac495271d0f', // DAI
    toTokenAddress: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',  // WETH
    amount: '1000000000000000000000', // 1000 DAI
    walletAddress,
    source: 'my-app'
  }

  const quote = await sdk.getQuote(params)

  console.log('Quote received:')
  console.log('Recommended preset:', quote.recommendedPreset)
  console.log('Auction start amount:', quote.presets[quote.recommendedPreset].auctionStartAmount)
  console.log('Auction end amount:', quote.presets[quote.recommendedPreset].auctionEndAmount)

  return { quote, params }
}
The quote includes:
  • Recommended preset: The optimal auction configuration (fast, medium, or slow)
  • Auction start amount: The initial (best) price for resolvers
  • Auction end amount: Your minimum acceptable price
  • Quote ID: Used when submitting the order
5

Create and submit the order

Create an order from the quote and submit it:
async function createAndSubmitOrder() {
  const walletAddress = computeAddress(PRIVATE_KEY)

  const params = {
    fromTokenAddress: '0x6b175474e89094c44da98b954eedeac495271d0f', // DAI
    toTokenAddress: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',  // WETH
    amount: '1000000000000000000000', // 1000 DAI
    walletAddress,
    source: 'my-app'
  }

  // Create the order
  const preparedOrder = await sdk.createOrder(params)
  console.log('Order created:', preparedOrder.hash)

  // Submit the order
  const result = await sdk.submitOrder(
    preparedOrder.order,
    preparedOrder.quoteId
  )

  console.log('Order submitted successfully!')
  console.log('Order hash:', result.orderHash)
  console.log('Signature:', result.signature)

  return result.orderHash
}
6

Monitor the order

Track your order status until it’s filled:
import { OrderStatus } from '@1inch/fusion-sdk'

async function waitForOrderFill(orderHash: string) {
  console.log('Monitoring order:', orderHash)
  const startTime = Date.now()

  while (true) {
    try {
      const status = await sdk.getOrderStatus(orderHash)

      if (status.status === OrderStatus.Filled) {
        console.log('✅ Order filled!')
        console.log('Transaction hash:', status.fills[0].txHash)
        console.log('Execution time:', (Date.now() - startTime) / 1000, 'seconds')
        break
      }

      if (status.status === OrderStatus.Expired) {
        console.log('❌ Order expired without execution')
        break
      }

      if (status.status === OrderStatus.Cancelled) {
        console.log('🚫 Order was cancelled')
        break
      }

      console.log('⏳ Order status:', status.status)
      await new Promise(resolve => setTimeout(resolve, 5000))

    } catch (error) {
      console.error('Error checking status:', error)
      await new Promise(resolve => setTimeout(resolve, 5000))
    }
  }
}
7

Run the complete example

Put it all together:
async function main() {
  try {
    // Get quote
    console.log('1. Getting quote...')
    const { quote, params } = await getSwapQuote()

    // Create and submit order
    console.log('\n2. Creating and submitting order...')
    const orderHash = await createAndSubmitOrder()

    // Monitor until filled
    console.log('\n3. Monitoring order...')
    await waitForOrderFill(orderHash)

  } catch (error) {
    console.error('Error:', error)
  }
}

main()
Run your script:
npx ts-node swap.ts

Complete example

Here’s the full working example you can copy and use:
import { 
  FusionSDK, 
  NetworkEnum, 
  OrderStatus,
  PrivateKeyProviderConnector,
  Web3Like 
} from '@1inch/fusion-sdk'
import { JsonRpcProvider, computeAddress } from 'ethers'

const PRIVATE_KEY = process.env.PRIVATE_KEY!
const RPC_URL = process.env.RPC_URL!
const API_TOKEN = process.env.API_TOKEN!

// Set up provider
const ethersProvider = new JsonRpcProvider(RPC_URL)
const web3Provider: Web3Like = {
  eth: {
    call(transactionConfig): Promise<string> {
      return ethersProvider.call(transactionConfig)
    }
  },
  extend(): void {}
}

const connector = new PrivateKeyProviderConnector(PRIVATE_KEY, web3Provider)

// Initialize SDK
const sdk = new FusionSDK({
  url: 'https://api.1inch.dev/fusion',
  network: NetworkEnum.ETHEREUM,
  blockchainProvider: connector,
  authKey: API_TOKEN
})

async function executeSwap() {
  const walletAddress = computeAddress(PRIVATE_KEY)

  const params = {
    fromTokenAddress: '0x6b175474e89094c44da98b954eedeac495271d0f', // DAI
    toTokenAddress: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',  // WETH
    amount: '1000000000000000000000', // 1000 DAI
    walletAddress,
    source: 'quickstart-example'
  }

  // Get quote
  const quote = await sdk.getQuote(params)
  console.log('Quote:', quote.presets[quote.recommendedPreset])

  // Create and submit order
  const preparedOrder = await sdk.createOrder(params)
  const result = await sdk.submitOrder(preparedOrder.order, preparedOrder.quoteId)
  console.log('Order hash:', result.orderHash)

  // Monitor status
  const startTime = Date.now()
  while (true) {
    const status = await sdk.getOrderStatus(result.orderHash)

    if (status.status === OrderStatus.Filled) {
      console.log('Filled in', (Date.now() - startTime) / 1000, 'seconds')
      console.log('TX:', status.fills[0].txHash)
      break
    }

    if ([OrderStatus.Expired, OrderStatus.Cancelled].includes(status.status)) {
      console.log('Order not filled:', status.status)
      break
    }

    await new Promise(resolve => setTimeout(resolve, 3000))
  }
}

executeSwap().catch(console.error)

Important notes

Approvals required: Before your first swap, you must approve the 1inch Limit Order contract to spend your tokens. The contract address is 0x111111125421ca6dc452d289314280a0f8842a65.
Balance check: Ensure your wallet has sufficient token balance before creating an order. Orders with insufficient balance will be marked as invalid.
Network selection: This example uses Ethereum mainnet. To use other networks, change the network parameter to NetworkEnum.POLYGON, NetworkEnum.BINANCE, etc.

What’s happening under the hood

When you submit a Fusion order:
  1. Order creation: Your swap parameters are converted into a signed limit order
  2. Auction starts: The order enters a Dutch auction where the acceptable price decreases over time
  3. Resolver competition: Professional market makers compete to fill your order at the best price
  4. Settlement: The first resolver to execute at the current auction price wins and settles on-chain
  5. Completion: You receive your tokens at the execution price

Next steps

Now that you’ve executed your first swap, explore more advanced features:

Native token swaps

Learn how to swap ETH, BNB, and other native tokens

Custom presets

Configure custom auction parameters for optimal pricing

Order management

Check order status, cancel orders, and query history

WebSocket integration

Real-time order updates with WebSocket API

Build docs developers (and LLMs) love