UI
SwapWidget
Swap Cross-Chain Instantly
Parameters
Parameter | Description | Required |
---|---|---|
defaultFromToken | An object representing a token that will be used as the default to swap from. | ✅ |
supportedWalletVMs | A required array of VMs that the swap widget should support, if a VM is selected that’s not listed it will fall back to the (deposit address)[https://support.relay.link/en/articles/10269920-how-do-deposit-addresses-work] ux. When setting this array make sure that the VMs are connectible by your wallet connection provider (dynamic, rainbow, privy, etc). | ✅ |
defaultToToken | An object representing a token that will be used as the default to swap to. | ❌ |
lockFromToken | Disables selecting a from token in the ui. A defaultFromToken is required in order for this setting to be applied. | ❌ |
lockToToken | Disables selecting a to token in the ui. A defaultToToken is required in order for this setting to be applied. | ❌ |
onFromTokenChange | A callback triggered when the user changes the from token | ❌ |
onToTokenChange | A callback triggered when the user changes the to token | ❌ |
lockChainId | If set, locks the chain selection to the specified chain ID. Requires default tokens to be configured for this to work properly. | ❌ |
tokens | An array of Token objects to restrict the available tokens for selection. | ❌ |
wallet | An AdaptedWallet object representing the user’s wallet. | ❌ |
multiWalletSupportEnabled | A boolean indicating whether multi-wallet (evm/svm) support is enabled. | ❌ |
linkedWallets | An array of LinkedWallet objects when multi-wallet support is enabled. | ❌ (✅ if multiWalletSupportEnabled is true) |
onSetPrimaryWallet | A callback function to set the primary wallet when multi-wallet support is enabled. | ❌ (✅ if multiWalletSupportEnabled is true) |
onLinkNewWallet | A callback function to link a new wallet when multi-wallet support is enabled. | ❌ (✅ if multiWalletSupportEnabled is true) |
defaultToAddress | A wallet address to send the proceeds to. | ❌ |
defaultAmount | The default amount to swap, the amount is in the from token currency. | ❌ |
defaultTradeType | This can either be EXACT_INPUT or EXACT_OUTPUT , each of these refers to prefilling the output amount or the input amount and having the quote return the other side. | ❌ |
slippageTolerance | Slippage tolerance for the swap, if not specified then the slippage tolerance is automatically calculated to avoid front-running. This value is in basis points (1/100th of a percent), e.g. 50 for 0.5% slippage. | ❌ |
onConnectWallet | A callback to connect the user’s wallet. The widget can be used to fetch quotes for unauthenticated sessions but executing the quote requires an authenticated session. | ✅ |
onAnalyticEvent | A callback which sends useful events to pipe into your existing analytics integration. | ❌ |
onSwapValidating | A callback that returns the quote object along with executable steps while validating the swap | ❌ |
onSwapSuccess | A callback that returns the quote object along with executable steps when the swap is complete | ❌ |
Usage
Slippage Configuration
The SlippageToleranceConfig
component provides a user interface for configuring slippage tolerance in basis points. This component handles all the complexity of managing slippage values including debouncing, input validation, and conversion between percentage and basis points.
Parameters
Parameter | Description | Required |
---|---|---|
setSlippageTolerance | Callback function to update the slippage tolerance value | ✅ |
onAnalyticEvent | Optional callback for analytics events | ❌ |