Building Transactions

The Typescript SDK provides multiple ways for you to create the transaction needed to execute specific actions on the Whirlpool contract.

1. Composing your own Transaction

Use the TransactionBuilder class to construct and compose your own Transactions to perform actions on the Whirlpools contract.

Whirlpools Instruction Set

const txBuilder = new TransactionBuilder(ctx.provider);
txBuilder.addInstruction(WhirlpoolIx.initializeConfigIx(ctx, configParams));
...
txBuilder.addInstruction(otherIx).addSigner(otherSigner);
...
await txBuilder.buildAndExecute();

Use to toTx function if you only have one transaction to send out

const tx = toTx(ctx, WhirlpoolIx.initializeConfigIx(ctx.program, configParams));
await txBuilder.buildAndExecute();

Read more on the Transaction Utils category here.

2. Simplified interaction with Whirlpool Client

In some occasions, certain actions require multiple instructions to complete. The SDK includes a WhirlpoolClient class to help construct these complex actions. For example, you can create a transaction to open a position and inject liquidity all in one go!

Read the WhirlpoolClient interface to see what else you can do with this class.

const context = new WhirlpoolContext(...);
const fetcher = new AccountFetcher(context.provider);
const client = new WhirlpoolClient(context, fetcher);
const pool = await client.getPool(poolAddress);

// Mints a position and insert liquidity (2 instructions)
const {tx: openPositionTx} = await pool.openPosition(...);
await openPositionTx.buildAndExecute();

// Withdraw all liquidity from a position and burn the position (2 instructions)
const closePositionTx = await pool.closePosition(...);
await closePositionTx.buildAndExecute();

Last updated