Mint an NFT and use FuturePass to pay gas fee

mint() and addFuturePass()

The example below shows how to mint an NFT on a Root Network Collection, but minting using the FuturePass to pay for the gas.

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 nftBuilder = await TransactionBuilder.nft(trnApi, signer, userSession.eoa, collectionId).mint({ quantity: 1, walletAddress: userSession?.futurepass }).addFuturePass(userSession.futurepass);

  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 -> ♾️