Batch

batch()

Creates a BatchBuilder class instance, which provides methods to build transactions for utility pallet batch extrinsics. It expects three parameters:

  • api: the trnApi to use for interaction.

  • signer: the signer to use for signing transactions.

  • walletAddress: the wallet address to use for interaction. Note: It should be the EOA address for the signer, not the FuturePass address.

Example:

  const tx1 = trnApi?.tx?.nft.mint(collectionId, 1, eoa);
  const tx2 = trnApi?.tx?.nft.mint(collectionId, 5, fp);
  const tx3 = trnApi?.tx?.assetsExt.transfer(1, fp, 1, true);
  const tx4 = trnApi?.tx?.assetsExt.transfer(2, fp, 10, true);
  const tx5 = trnApi?.tx?.nft.mint(collectionId, 3, eoa);

  const batchBuilder = await TransactionBuilder.batch(api, signer, walletAddress).addExtrinsic(tx1).addExtrinsic(tx2).addExtrinsic(tx3).addExtrinsic(tx4).addExtrinsic(tx5).batchAll();

The batch method provides developers with capabilities to addExtrinsic, addExtrinsics, batch, batchAll, batchAllWithExtrinsics, and batchWithExtrinsics.

addExtrinsic()

Adds an extrinsic to be used in a batch() or batchAll() call. It expects one parameter:

  • extrinsic: the extrinsic to add to the batch.

Example:

const tx1 = trnApi?.tx?.nft.mint(collectionId, 1, eoa);

const batchBuilder = await TransactionBuilder.batch(api, signer, walletAddress).addExtrinsic(tx1).addExtrinsic(tx2).batchAll();

addExtrinsics()

Adds multiple extrinsics to be used in a batch() or batchAll() call. It expects one parameter:

  • extrinsics: an array of extrinsics to add to the batch.

Example:

const tx = [trnApi?.tx?.nft.mint(collectionId, 1, eoa), trnApi?.tx?.nft.mint(collectionId, 5, fp)];

const batchBuilder = await TransactionBuilder.batch(api, signer, walletAddress).addExtrinsics(tx).batch();
// or
const batchBuilder = await TransactionBuilder.batch(api, signer, walletAddress).addExtrinsics(tx).batchAll();

batch()

Batch all extrinsics set into a single transaction and sets the base extrinsic to the batch. It has no parameters.

This method will return Ok in all circumstances. It will batch all extrinsics into a single transaction. It will finalize and succeed regardless of whether any extrinsic in the batch fails.

Example:

const batchBuilder = await TransactionBuilder.batch(api, signer, walletAddress).addExtrinsic(tx1).addExtrinsic(tx2).addExtrinsic(tx3).batch()

// or

const tx = [trnApi?.tx?.nft.mint(collectionId, 1, eoa), trnApi?.tx?.nft.mint(collectionId, 5, fp)];

const batchBuilder = await TransactionBuilder.batch(api, signer, walletAddress).addExtrinsics(tx).batch();

batchAll()

Batch all extrinsics set into a single transaction and sets the base extrinsic to the batch all extrinsic (e.g: individually added by addExtrinsic). It has no parameters.

This method will batch all extrinsics into a single transaction. If any extrinsic fails, the entire transaction will fail.

Example:

const batchBuilder = await TransactionBuilder.batch(api, signer, walletAddress).addExtrinsic(tx1).addExtrinsic(tx2).addExtrinsic(tx3).addExtrinsic(tx4).batchAll();

batchAllWithExtrinsics()

Builds a batch with the provided extrinsics and sets the base extrinsic to the batchAll() extrinsic. It expects one parameter:

  • extrinsics: an array of extrinsics to include in the single transaction.

This method will batch all extrinsics into a single transaction. If any extrinsic fails, the entire transaction will fail.

Example:

const tx = [trnApi?.tx?.nft.mint(collectionId, 1, eoa), trnApi?.tx?.nft.mint(collectionId, 5, fp)]

const batchBuilder = await TransactionBuilder.batch(api, signer, walletAddress).batchWithEx

batchWithExtrinsics()

Builds a batch with the provided extrinsics and sets the base extrinsic to the batch. It expects one parameter:

  • extrinsics: an array of extrinsics to include in the single transaction.

This method will return Ok in all circumstances. It will batch all extrinsics into a single transaction. It will finalize and succeed regardless of whether any extrinsic in the batch fails.

Example:

const tx = [trnApi?.tx?.nft.mint(collectionId, 1, eoa), trnApi?.tx?.nft.mint(collectionId, 5, fp)]

const batchBuilder = await TransactionBuilder.batch(api, signer, walletAddress).batchWithExtrinsics(tx);

More examples of the methods above can be found in Guides.

Last updated

© 2023 -> ♾️