ERC-1155 tokens are non-fungible tokens that are best for categorical value attribution. Learn more here

This example guides you to create and mint ERC-1155 NFT to their NFT Account. For example, mint ‘Early Bird’ badge when user is one of the first 100 people to RSVP via the application.

Pre-requisite

Create an ERC-1155 NFT collection

  1. In the Dashboard, go to the ‘Tokens’ tab.
  2. Click ’+ New Tokens’ and select ‘ERC-1155’ option
  3. Fill out the token details and click ‘Next’.
  4. Review the details and click ‘Done’.
  5. Find and copy the collection contract address.

Mint an NFT to Accounts

If the user is transacting as their EoA that owns the NFT Account:

1. Query NFT ID

First, you need to query the token IDs of the NFT Accounts that the EoA owns using the /api/v1/erc721/tokens route.

In JavaScript, calling the API would look like the following:

const nft = {
  chainId: 5, // goerli testnet
  contractAddress: "0x...",
  ownerAddress: "0x...", // address of the connected EoA
};

const response = await fetch(
  "https://groupos.xyz/api/v1/erc6551/account" +
    new URLSearchParams({
      tokenChainId: nft.chainId,
      tokenContractAddress: nft.contractAddress,
      ownerAddress: nft.ownerAddress,
    }),
  {
    method: "GET",
    headers: {
      Authorization: `Bearer ${process.env.GROUPOS_API_KEY}`,
    },
  }
)

const allTokens = await response.json().tokens;

This returns an array of token IDs of the NFT Accounts that the EoA owns. Here, you may want to let the user pick which NFT Account they would like to mint the ERC-1155 NFT into.

2. Query an Account address

Assuming that you know the token ID, you then need to query the associated Account address using the /api/v1/erc6551/account route.

In JavaScript, calling the API would look like the following:

const nft = {
  chainId: 5, // goerli testnet
  contractAddress: "0x...",
  id: 1, // token ID
};

const response = await fetch(
  "https://groupos.xyz/api/v1/erc6551/account" +
    new URLSearchParams({
      tokenChainId: nft.chainId,
      tokenContractAddress: nft.contractAddress,
      tokenId: nft.Id,
    }),
  {
    method: "GET",
    headers: {
      Authorization: `Bearer ${process.env.GROUPOS_API_KEY}`,
    },
  }
)

const accountAddress = await response.json().account.contractAddress;

3. Mint NFT and send to Account

With the Account address, you can mint the NFT to the Account using /api/v1/erc1155/mint route.

In JavaScript, calling the API would look like the following:

const nft = {
  chainId: 5, // goerli testnet
  contractAddress: "0x...",
  recipientAddress: "0x...", // account address
  tokenId: 1, // ERC-1155 variant 
  amount: 1, 
};

const response = await fetch("https://groupos.xyz/api/v1/erc1155/mint", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.GROUPOS_API_KEY}`,
  },
  body: JSON.stringify({
    chainId: nft.chainId,
    contractAddress: nft.contractAddress,
    recipientAddress: nft.recipientAddress,
    tokenId: nft.tokenId,
    amount: nft.amount,
  }),
})

const transactionHash = await response.json().transactionHash;

If the user is transacting as their NFT Account:

With the Account address, you can mint the NFT to the Account using /api/v1/erc1155/mint route.

In JavaScript, calling the API would look like the following:

const nft = {
  chainId: 5, // goerli testnet
  contractAddress: "0x...",
  recipientAddress: "0x...", // account address
  tokenId: 1, // ERC-1155 variant 
  amount: 1, 
};

const response = await fetch("https://groupos.xyz/api/v1/erc1155/mint", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.GROUPOS_API_KEY}`,
  },
  body: JSON.stringify({
    chainId: nft.chainId,
    contractAddress: nft.contractAddress,
    recipientAddress: nft.recipientAddress,
    tokenId: nft.tokenId,
    amount: nft.amount,
  }),
})

const transactionHash = await response.json().transactionHash;

Confirm

You can query the minted NFTs for confirmation. Using the /api/v1/erc1155/tokens route, you can query the list of all owners and also tokens for just the latest recipient.

In JavaScript, calling the API would look like the following:

const nft = {
  chainId: 5, // goerli testnet
  contractAddress: "0x...",
  ownerAddress: "0x...", // account address
};

const response = await fetch(
  "https://groupos.xyz/api/v1/erc1155/tokens" +
    new URLSearchParams({
      chainId: nft.chainId,
      contractAddress: nft.contractAddress,
      ownerAddress:nft.ownerAddress,
    }),
  {
    method: "GET",
    headers: {
      Authorization: `Bearer ${process.env.GROUPOS_API_KEY}`,
    },
  }
)

const allTokens = await response.json().tokens;

You can find other API routes to perform other ERC-1155 NFT operations here.