For the complete documentation index, see llms.txt. This page is also available as Markdown.

mega.swap()

Open the wallet-managed swap flow for token exchange. The wallet handles routing UI, slippage, confirmation, and execution.

Signature

mega.swap(request: SwapRequest): Promise<TransactionResult>

Parameters

Field
Type
Required
Notes

fromToken

`0x${string}` / 'native'

optional

Pre-select source token.

toToken

`0x${string}` / 'native'

optional

Pre-select destination token.

Example

const result = await mega.swap({
  fromToken: 'native',
  toToken: '0xTokenAddress',
});

if (result.status === 'error') {
  console.error(result.error);
}

Response

Shared TransactionResult shape.

Notes

Treat cancelled as user intent — avoid hard-failing app state. For programmatic contract calls (custom swap router, batch operations), use callContract() instead.

Last updated