safeMint
The safeMint
method is an integral feature of the ERC-721 token standard, designed for managing non-fungible tokens (NFTs) on the Ethereum blockchain. It facilitates the creation and assignment of a new NFT to a specified Ethereum address. The term "safe" in safeMint
emphasizes the method's capability to ensure that the recipient address can safely handle NFTs, thereby guarding against potential vulnerabilities.
This method is encapsulated within the ERC721Instance
object, accessible via appropriate client library functions, such as ZkyugaClient
.
Method Signature
async safeMint(recipient: string, tokenURI: string, signer: WalletSigner): Promise<TransactionResponse>
Parameters
recipient
string
The Ethereum address designated to receive the newly minted non-fungible token (NFT).
tokenURI
string
A unique resource identifier string pointing to the metadata of the token, typically referencing a JSON file describing the properties and attributes of the NFT.
signer
WalletSigner
The signer instance responsible for initiating and signing the transaction. This can originate from various sources, such as software wallets, hardware wallets, or private key storage solutions.
Returns
A
Promise
resolving to aTransactionResponse
object, furnishing comprehensive details about the minting transaction, including its status, transaction hash, and more.
Usage Example
Start by obtaining an instance of the desired ERC-721 token contract:
const erc721 = zkyugaClient.getERC721Instance("your ERC-721 contract address here");
Then, utilize the safeMint
method to create a new NFT securely:
const recipientAddress = "0xExampleRecipientAddressHere";
const metadataURI = "https://example.com/token/1012.json"; // An example token metadata URI
const signer = zkyugaClient.createWalletSigner("your private key");
const transactionResponse = await erc721.safeMint(recipientAddress, metadataURI, signer);
console.log(`Minting Transaction Hash: ${transactionResponse.hash}`);
Notes
Verify that the minting address (associated with the signer) possesses the requisite permissions or roles to mint tokens, as specified in the ERC-721 contract.
The
tokenURI
typically points to metadata regarding the NFT, such as its name, image, description, and other attributes. Ensure it is both accessible and correctly formatted.The
safeMint
method conducts a check to ascertain whether the recipient address can handle ERC-721 tokens. If not, the minting process is aborted to prevent tokens from being sent to contracts or addresses unable to manage them.
Last updated