Create a collection

createCollection()

The example below shows how to create a collection.

const transaction = await TransactionBuilder.nft(
      trnApi,
      signer,
      userSession.eoa,
      collectionId
    )

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

    if (
      !collectionName ||
      !metadataUri ||
      collectionName === '' ||
      metadataUri === ''
    ) {
      console.log('Missing collectionName or metadataUri');
      return;
    }

    if (royalties && royalties.length > 0) {
      if (
        royalties.some((r) => r[0] === '' || !isAddress(r[0]) || r[1] === 0)
      ) {
        console.log('Invalid Royalties');
        return;
      }
    }

    await transaction.createCollection({
      name: collectionName,
      initialIssuance,
      maxIssuance,
      tokenOwner,
      metadataUri,
      royalties,
      crossChain,
    });

    if (assetId !== 2) {
      if (useFuturePass) {
        await transaction.addFuturePassAndFeeProxy({
          futurePass: userSession.futurepass,
          assetId: assetId,
          slippage: slippage === '' ? 5 : Number(slippage),
        });
      }
      if (!useFuturePass) {
        await transaction.addFeeProxy({
          assetId: assetId,
          slippage: slippage === '' ? 5 : Number(slippage),
        });
      }
    }
    if (assetId === 2) {
      if (useFuturePass) {
        await transaction.addFuturePass(userSession.futurepass);
      }
    }

    getExtrinsic(transaction);
    setCurrentBuilder(transaction);
  }, [
    trnApi,
    signer,
    userSession,
    collectionName,
    metadataUri,
    transaction,
    initialIssuance,
    maxIssuance,
    tokenOwner,
    royalties,
    crossChain,
    assetId,
    useFuturePass,
    slippage,
  ]);

Last updated

© 2023 -> ♾️