run

Therun method executes the actions generated by the getActions method to complete a purchase transaction. This method first approves the required amount of funds and then executes the buy transaction.

Parameters

An IBuyConfig object which contains:

  • saleId: The ID of the sale to purchase fractions from.
  • chainId: The blockchain chain ID where the sale is registered.
  • amountToBuy: The amount of fractions to buy.

Returns

Promise<IBuyOutput> - A promise that resolves to the result of the actions execution, including transaction details and the updated context.

Usage


// Step 1: Generate actions for the purchase
const actions = sdk.buyService.getActions();
actions.on('nextAction', (state) => {
  console.log('Current action state:', state);
});

// Step 2: Prepare the configuration for the purchase
const buyConfig = {
  saleId: 1, // ID of the sale
  chainId: 1, // ID of the blockchain network
  amountToBuy: BigInt(100), // Amount of fractions to buy
};

// Step 3: Execute the actions to complete the purchase
try {
  const result = await actions.run(buyConfig);
  console.log('Purchase completed successfully:', result);
} catch (error) {
  console.error('Error during purchase:', error);
}