mint
The mint
method for the ERC-1155 token standard facilitates the creation of a specified quantity of a token with a given ID for a specified Ethereum address. This functionality is pivotal for various applications, such as issuing rewards or creating new token batches. The method is incorporated within the ERC1155Instance
object, which can be fetched through the relevant method of the EdexaClient
or a similar library.
Method Signature
async mint(
userAddress: string,
id: string,
amount: string,
data: string = "0x",
signer: WalletSigner
): Promise<TransactionResponse>
Parameters
Parameter | Type | Description |
---|---|---|
userAddress | string | The Ethereum address receiving the minted tokens. |
id | string | The specific ID of the ERC-1155 token to be minted. |
amount | string | The quantity of the token to be minted for the provided ID. |
data | string | Additional data or bytes to accompany the minting function, defaulting to "0x". |
signer | WalletSigner | The wallet signer instance responsible for signing the transaction. |
Returns
- A
Promise
resolving to aTransactionResponse
, which contains details about the minting transaction.
Usage Example
First, instantiate the desired ERC-1155 token contract:
const erc1155 = edexaClient.getERC1155Instance("your ERC-1155 contract address here");
Then, call the mint
method with the appropriate parameters:
const recipientAddress = "0x2c360D20cE6b3D8b466511eF093C9177c3817B94";
const tokenId = "specific-token-id";
const mintAmount = "100";
const dataBytes = "0x"; // Optional data bytes
const signer = edexaClient.createWalletSigner("your private key");
const mintTransaction = await erc1155.mint(recipientAddress, tokenId, mintAmount, dataBytes, signer);
console.log(`Mint Transaction Hash: ${mintTransaction.hash}`);
Notes
The
mint
method enables the dynamic creation of ERC-1155 tokens. Ensure proper permissions when invoking this method, as unrestricted minting can lead to vulnerabilities or imbalances.Always validate the Ethereum address, token ID, and other parameters before invoking the
mint
method to prevent errors or unintentional minting.