Skip to main content

Minting ERC721 Tokens

Minting ERC721 tokens is a fundamental operation in the lifecycle of Non-Fungible Tokens (NFTs), allowing the creation of unique digital assets. The edeXa ERC721 SDK provides a streamlined method, mintToken, to perform this operation. This guide outlines the process and provides a code example for minting tokens.


Overview of the mintToken Method

The mintToken method enables the creation of new tokens within the ERC721 standard. Each minted token is unique and is associated with specific metadata through a unique URI.


Prerequisites

  • Installation of the edeXa ERC721 SDK in your project.
  • An authentication token obtained through the SDK's authentication method. This token is necessary to authorize your requests.

Sample Code Snippet

Here is a JavaScript code snippet demonstrating the use of the mintToken method:

import { ERC721, Network } from 'edeXa-sdk';
async function mintToken() {
const settings = {
network: Network.SANDBOX, // Or Network.MAINNET for production environments
};
const erc721 = new ERC721({
...settings,
authorization: `Bearer ${token}`, // Replace `${token}` with your actual authentication token
});

const dataToMintToken = {
tokenUrl: 'Enter the token URL', // Required URL for the token metadata
chaincode: 'Optional smart contract name', // Managing tokens' smart contract name
channel: 'Optional blockchain channel name', // Blockchain channel name
};

try {
const mintTokenResponse = await erc721.mintToken(dataToMintToken);
// Handle success
} catch (error) {
// Handle error
}
}

Request Parameters

ParameterRequiredTypeDescriptionDefault
userIdYesStringThe uuid of the user for whom to retrieve the account ID
chaincodeOptionalStringThe name of the smart contract managing the tokensDefault chaincode
channelOptionalStringThe name of the channel in the blockchain networkDefault channel

Response Format

The successful execution of the mintToken method returns a response containing details of the minted token.

KeyTypeDescription
tokenIdNumberThe unique identifier of the minted token.
tokenURIStringThe URI associated with the minted token's metadata.
minterStringThe username or identifier of the entity that minted the token.