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
Parameter | Required | Type | Description | Default |
---|---|---|---|---|
userId | Yes | String | The uuid of the user for whom to retrieve the account ID | |
chaincode | Optional | String | The name of the smart contract managing the tokens | Default chaincode |
channel | Optional | String | The name of the channel in the blockchain network | Default channel |
Response Format
The successful execution of the mintToken
method returns a response containing details of the minted token.
Key | Type | Description |
---|---|---|
tokenId | Number | The unique identifier of the minted token. |
tokenURI | String | The URI associated with the minted token's metadata. |
minter | String | The username or identifier of the entity that minted the token. |