Batch

addExtrinsic() and batchAll()

The example below shows how to batch multiple transactions on The Root Network Collection together, using addExtrinsic() and batchAll(), and send them using the FuturePass to pay the gas combined with the fee proxy to pay with a chosen token.

The examples shown in this section include Futureverse Auth for authentication.

Example:

import { useAuth, useFutureverseSigner } from '@futureverse/auth-react';
import { TransactionBuilder } from '@futureverse/transact';
import { useTrnApi } from 'providers/TRNProvider';

const { userSession } = useAuth();
const [builder, setBuilder] = useState();
const signer = useFutureverseSigner();
const { trnApi } = useTrnApi();
const collectionId = '709732';

const triggerInit = useCallback(async () => {
  if (!trnApi || !signer || !userSession) {
    return null;
  }

  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(trnApi, signer, userSession.eoa).addExtrinsic(tx1).addExtrinsic(tx2).addExtrinsic(tx3).addExtrinsic(tx4).addExtrinsic(tx5).batchAll().addFuturePassAndFeeProxy({
    futurePass: userSession.futurepass,
    assetId: assetId,
    slippage: 5,
  });

  setBuilder(nftBuilder);
}, [trnApi, signer, userSession]);

const signExtrinsic = useCallback(async () => {
  if (builder) {
    const result = await builder?.signAndSend({ onSign, onSend });
    setResult(result as ExtrinsicResult);
  }
}, [builder, onSend, onSign, toSign]);

return (
  <>
    <button
      onClick={() => {
        triggerInit();
      }}
    >
      Mint 1 Nft
    </button>

    <button
      onClick={() => {
        signExtrinsic();
      }}
    >
      Sign &amp; Send
    </button>
  </>
);

Last updated

© 2023 -> ♾️