Skip to main content

Class: Swaps

Service for handling token swap operations.

Constructors

Constructor

new Swaps(bundlerService, options?): Swaps;

Parameters

ParameterType
bundlerServiceBundler
options?{ walletAddress?: string; }
options.walletAddress?string

Returns

Swaps

Methods

swap()

swap(
tokenIn,
tokenOut,
fee,
amount,
walletAddress?): Promise<PendingTransaction>;

Executes a token swap transaction.

Parameters

ParameterTypeDescription
tokenIn| string | GalaChainTokenClassKeyThe input token to sell.
tokenOut| string | GalaChainTokenClassKeyThe output token to buy.
feenumberThe pool fee tier.
amount| { amountOutMinimum?: NumericAmount; exactIn: NumericAmount; } | { amountInMaximum?: NumericAmount; exactOut: NumericAmount; }Swap parameters specifying either exact input or exact output.
walletAddress?stringThe wallet address executing the swap.

Returns

Promise<PendingTransaction>

Pending transaction.

Example

// Exact input swap: sell 100 GALA for USDC
const result = await swapsService.swap(
'GALA|Unit|none|none',
'GUSDC|Unit|none|none',
500,
{ exactIn: '100', amountOutMinimum: '45' },
'eth|123...abc', // your wallet address
);
console.log('Swap successful:', result);