Installation
Get started with the 1inch Cross Chain SDK by installing the package and setting up your development environment.
Package Installation
Install the SDK using your preferred package manager:
npm install @1inch/cross-chain-sdk
Requirements
The SDK requires Node.js version 18.16.0 or higher. Check your Node version with node --version.
Peer Dependencies
The SDK has one optional peer dependency:
{
"peerDependencies": {
"assert": "^2.0.0"
}
}
This dependency is automatically handled by most package managers and is only required in certain environments.
Setup with Web3.js
If you’re using Web3.js as your blockchain provider, here’s how to initialize the SDK:
Import dependencies
import { SDK, PrivateKeyProviderConnector, NetworkEnum } from '@1inch/cross-chain-sdk'
import Web3 from 'web3'
Configure your environment
const privateKey = '0x...' // Your wallet private key
const rpc = 'https://ethereum-rpc.publicnode.com' // RPC endpoint
const authKey = 'your-auth-key' // Get from https://portal.1inch.dev
const source = 'sdk-tutorial' // Identifier for your integration
Never hardcode private keys in production. Use environment variables or secure key management solutions.
Initialize Web3 and wallet
const web3 = new Web3(rpc)
const walletAddress = web3.eth.accounts.privateKeyToAccount(privateKey).address
Create SDK instance
const sdk = new SDK({
url: 'https://api.1inch.com/fusion-plus',
authKey,
blockchainProvider: new PrivateKeyProviderConnector(privateKey, web3)
})
The blockchainProvider is only required for creating orders. You can omit it if you only need to fetch quotes or query order status.
Setup with Ethers.js
For Ethers.js v6 users, create a custom provider connector:
Import dependencies
import { SDK, PrivateKeyProviderConnector } from '@1inch/cross-chain-sdk'
import { JsonRpcProvider, Wallet } from 'ethers'
Create provider connector
const ethersRpcProvider = new JsonRpcProvider('https://ethereum-rpc.publicnode.com')
const ethersProviderConnector = {
eth: {
call(transactionConfig): Promise<string> {
return ethersRpcProvider.call(transactionConfig)
}
},
extend(): void {}
}
Initialize SDK with Ethers provider
const privateKey = '0x...'
const authKey = 'your-auth-key'
const connector = new PrivateKeyProviderConnector(
privateKey,
ethersProviderConnector
)
const sdk = new SDK({
url: 'https://api.1inch.com/fusion-plus',
authKey,
blockchainProvider: connector
})
const wallet = new Wallet(privateKey, ethersRpcProvider)
Authentication
All SDK requests require an authentication key from the 1inch Developer Portal.
Visit the Developer Portal
Generate an API key
Go to the API Keys section and generate a new key for the Fusion+ API.
Store securely
Add your API key to your environment variables:INCH_AUTH_KEY=your-api-key-here
Use in SDK configuration
const sdk = new SDK({
url: 'https://api.1inch.com/fusion-plus',
authKey: process.env.INCH_AUTH_KEY,
blockchainProvider: connector
})
SDK Configuration Options
The SDK constructor accepts the following configuration parameters:
| Parameter | Type | Required | Description |
|---|
url | string | Yes | Fusion+ API endpoint (use https://api.1inch.com/fusion-plus) |
authKey | string | Yes | Your 1inch Developer Portal API key |
blockchainProvider | BlockchainProviderConnector | No | Provider for signing transactions (required for order creation) |
httpProvider | HttpProviderConnector | No | Custom HTTP client for API requests |
Verify Installation
Test your setup by fetching a quote:
import { SDK, NetworkEnum } from '@1inch/cross-chain-sdk'
const sdk = new SDK({
url: 'https://api.1inch.com/fusion-plus',
authKey: process.env.INCH_AUTH_KEY
})
async function test() {
const quote = await sdk.getQuote({
srcChainId: NetworkEnum.POLYGON,
dstChainId: NetworkEnum.BINANCE,
srcTokenAddress: '0xc2132d05d31c914a87c6611c10748aeb04b58e8f', // USDT on Polygon
dstTokenAddress: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', // BNB
amount: '10000000', // 10 USDT
enableEstimate: true
})
console.log('Quote received:', quote)
}
test()
If you see quote data in your console, you’re ready to start building!
Next Steps
Quickstart Guide
Build your first cross-chain swap
EVM to EVM Swaps
Learn the complete swap workflow