Skip to main content

Overview

The Cross Chain SDK re-exports provider connectors from @1inch/fusion-sdk that enable integration with various Web3 libraries. These connectors handle blockchain interactions, transaction signing, and typed data signing required for order creation.

Provider Connectors

PrivateKeyProviderConnector

A provider connector that uses a private key for signing operations. This is the most common connector for server-side applications and scripts.
import { PrivateKeyProviderConnector, SDK } from '@1inch/cross-chain-sdk'
import Web3 from 'web3'

const privateKey = '0x...'
const rpc = 'https://ethereum-rpc.publicnode.com'
const web3 = new Web3(rpc)

const connector = new PrivateKeyProviderConnector(privateKey, web3)

const sdk = new SDK({
  url: 'https://api.1inch.com/fusion-plus',
  authKey: 'your-auth-key',
  blockchainProvider: connector
})

Usage with Ethers.js

import { PrivateKeyProviderConnector, SDK } from '@1inch/cross-chain-sdk'
import { JsonRpcProvider } from 'ethers'

const privateKey = '0x...'
const nodeUrl = 'https://ethereum-rpc.publicnode.com'
const ethersRpcProvider = new JsonRpcProvider(nodeUrl)

const ethersProviderConnector = {
  eth: {
    call(transactionConfig) {
      return ethersRpcProvider.call(transactionConfig)
    }
  },
  extend() {}
}

const connector = new PrivateKeyProviderConnector(
  privateKey,
  ethersProviderConnector
)

const sdk = new SDK({
  url: 'https://api.1inch.com/fusion-plus',
  authKey: 'your-auth-key',
  blockchainProvider: connector
})

Web3ProviderConnector

A connector for Web3.js provider instances. Use this when you have an existing Web3 provider instance.
import { Web3ProviderConnector, SDK } from '@1inch/cross-chain-sdk'
import Web3 from 'web3'

const web3 = new Web3('https://ethereum-rpc.publicnode.com')
const connector = new Web3ProviderConnector(web3)

const sdk = new SDK({
  url: 'https://api.1inch.com/fusion-plus',
  authKey: 'your-auth-key',
  blockchainProvider: connector
})

HttpProviderConnector

A connector for HTTP-based RPC providers. Use this for custom HTTP provider configurations.
import { HttpProviderConnector, SDK } from '@1inch/cross-chain-sdk'

const httpProvider = new HttpProviderConnector('https://ethereum-rpc.publicnode.com')

const sdk = new SDK({
  url: 'https://api.1inch.com/fusion-plus',
  authKey: 'your-auth-key',
  httpProvider // Note: used for API calls, not blockchain signing
})

WsProviderConnector

A connector for WebSocket-based RPC providers. Use this when you need real-time updates or WebSocket connections.
import { WsProviderConnector } from '@1inch/cross-chain-sdk'

const wsProvider = new WsProviderConnector('wss://ethereum-rpc.publicnode.com')

BlockchainProviderConnector

The base interface that all provider connectors implement. This defines the contract for signing typed data and interacting with the blockchain.
interface BlockchainProviderConnector {
  signTypedData(walletAddress: string, typedData: EIP712TypedData): Promise<string>
  eth: {
    call(transactionConfig: any): Promise<string>
  }
  extend(): void
}

SDK Configuration

When creating the SDK instance, you can provide provider connectors through the configuration:
import { SDK, PrivateKeyProviderConnector, HttpProviderConnector } from '@1inch/cross-chain-sdk'

const sdk = new SDK({
  url: 'https://api.1inch.com/fusion-plus',
  authKey: 'your-auth-key',
  blockchainProvider: connector, // For signing operations (order creation)
  httpProvider: httpConnector     // Optional: for API HTTP requests
})

Configuration Parameters

url
string
required
The base URL for the 1inch Fusion Plus API
authKey
string
Your API authentication key from the 1inch Developer Portal
blockchainProvider
BlockchainProviderConnector
Provider connector for signing operations. Required for creating and submitting orders.
httpProvider
HttpProviderConnector
Optional HTTP provider for API requests

When to Use Each Connector

PrivateKeyProviderConnector

Best for server-side applications, scripts, and automated trading bots where you have direct access to private keys.

Web3ProviderConnector

Use when integrating with existing Web3.js applications or when you need to support browser-based wallets.

HttpProviderConnector

For custom HTTP RPC configurations and API request handling.

WsProviderConnector

When you need WebSocket connections for real-time blockchain data or events.

Common Use Cases

Creating Orders

The blockchainProvider is required when creating orders because it needs to sign the order data:
import { SDK, PrivateKeyProviderConnector, NetworkEnum } from '@1inch/cross-chain-sdk'
import Web3 from 'web3'

const web3 = new Web3('https://ethereum-rpc.publicnode.com')
const connector = new PrivateKeyProviderConnector('0x...', web3)

const sdk = new SDK({
  url: 'https://api.1inch.com/fusion-plus',
  authKey: 'your-auth-key',
  blockchainProvider: connector // Required for order creation
})

// Now you can create and submit orders
const { hash, quoteId, order } = await sdk.createOrder(quote, {
  walletAddress,
  hashLock,
  preset,
  source: 'my-app',
  secretHashes
})

Read-Only Operations

For read-only operations like getting quotes or checking order status, you don’t need a blockchain provider:
import { SDK, NetworkEnum } from '@1inch/cross-chain-sdk'

const sdk = new SDK({
  url: 'https://api.1inch.com/fusion-plus',
  authKey: 'your-auth-key'
  // No blockchainProvider needed for read operations
})

// Get a quote
const quote = await sdk.getQuote({
  amount: '10000000',
  srcChainId: NetworkEnum.POLYGON,
  dstChainId: NetworkEnum.BINANCE,
  srcTokenAddress: '0xc2132d05d31c914a87c6611c10748aeb04b58e8f',
  dstTokenAddress: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
  walletAddress,
  enableEstimate: true
})

// Check order status
const status = await sdk.getOrderStatus(orderHash)

Error Handling

When a blockchain provider is required but not configured:
try {
  const signature = await sdk.signOrder(order, srcChainId)
} catch (error) {
  // Error: 'blockchainProvider has not set to config'
}
Always ensure your blockchainProvider is configured when performing operations that require signing, such as creating orders or submitting transactions.

Security Best Practices

Private Key Security
  • Never hardcode private keys in your source code
  • Use environment variables or secure key management systems
  • Rotate keys regularly
  • Use different keys for development and production
// Good: Use environment variables
const privateKey = process.env.PRIVATE_KEY
const connector = new PrivateKeyProviderConnector(privateKey, web3)

// Bad: Hardcoded private key
const connector = new PrivateKeyProviderConnector('0x123...', web3)

EIP712TypedData

Used for EIP-712 typed data signing:
import { EIP712TypedData } from '@1inch/cross-chain-sdk'

// The provider connector uses this type for signing
interface EIP712TypedData {
  types: Record<string, Array<{ name: string; type: string }>>
  primaryType: string
  domain: Record<string, any>
  message: Record<string, any>
}

See Also

Build docs developers (and LLMs) love