Class: Swaps
Service for handling token swap operations.
Constructors
Constructor
new Swaps(bundlerService, options?): Swaps;
Parameters
Parameter | Type |
---|---|
bundlerService | Bundler |
options? | { walletAddress? : string ; } |
options.walletAddress? | string |
Returns
Swaps
Methods
swap()
swap(
tokenIn,
tokenOut,
fee,
amount,
walletAddress?): Promise<PendingTransaction>;
Executes a token swap transaction.
Parameters
Parameter | Type | Description |
---|---|---|
tokenIn | | string | GalaChainTokenClassKey | The input token to sell. |
tokenOut | | string | GalaChainTokenClassKey | The output token to buy. |
fee | number | The pool fee tier. |
amount | | { amountOutMinimum? : NumericAmount ; exactIn : NumericAmount ; } | { amountInMaximum? : NumericAmount ; exactOut : NumericAmount ; } | Swap parameters specifying either exact input or exact output. |
walletAddress? | string | The 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);