Swap Exact Input
Spend fixed source amounts and receive whatever the quote delivers on the destination chain.
swapWithExactIn() spends the exact raw amount you set on each source and delivers the quoted output to the destination token. It needs an initialized client.
Signature
swapWithExactIn(
input: SwapExactInParams,
options?: SwapOperationOptions,
): Promise<IntentResult>Parameters
| Name | Type | Description |
|---|---|---|
sources | Array<{ chainId: number; tokenAddress: Hex; amountRaw: bigint }> | Required, non-empty. Each amountRaw must be greater than 0n. |
toChainId | number | Required. Destination chain ID. |
toTokenAddress | Hex | Required. Destination token address. |
options | SwapOperationOptions | Optional. Slippage, timeouts, quote review, and events. See review quotes. |
getAvailableSourceTokens(destination, selectedSources).
To bridge the same asset, use that asset's address on each chain.
Example
import { parseUnits } from '@avail-project/nexus-core/utils';
const source = {
chainId: 1,
tokenAddress: '0xA0b86991c6218b36c1d19d4a2e9eb0cE3606eB48', // USDC on Ethereum
} as const;
const sourceToken = await client.getToken(source);
const result = await client.swapWithExactIn({
sources: [{ ...source, amountRaw: parseUnits('25', sourceToken.decimals) }],
toChainId: 8453,
toTokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC on Base
});
console.log(result.intentId, result.intentExplorerUrl);onIntent hook, the SDK accepts the first quote automatically.
Returns
IntentResult after the destination fill.
Before a wallet connects, the call works as a rate preview: it returns a quote for display, then rejects instead of executing.
Errors
Code (ERROR_CODES.*) | Cause |
|---|---|
INVALID_INPUT | Empty sources, a missing tokenAddress, a non-positive amountRaw, no shared provider, or slippageBps out of range. |
WALLET_NOT_CONNECTED | The quote was accepted without a connected wallet. |
USER_INTENT_HOOK_DENIED | Your hook called deny(). |
BACKEND_INSUFFICIENT_BALANCE | The wallet cannot cover the quoted inputs. |
BACKEND_FULFILMENT_WAIT_TIMEOUT | No fill within fillTimeoutMinutes. The intent can still fill. |
ENVIRONMENT_NOT_SUPPORTED | The client uses network: 'testnet'. |
How is this guide?