mint
The mint
method is employed to produce and assign a determined quantity of tokens to a specific Ethereum address. This function is predominantly associated with Mintable ERC20 tokens. Typically, only particular roles, like the owner or minter role within a token contract, can execute this function. The availability and operation of this method hinge on the unique implementation of the ERC20 token. Here, we're assuming the method is a feature of the ERC20Instance
object, which is derived from the getERC20Instance
function of the EdexaClient
.
Method Signature
async mint(to: string, amount: BigNumberish, signer: WalletSigner): Promise<TransactionResponse>
Parameters
Parameter | Type | Description |
---|---|---|
to | string | The Ethereum address designated to receive the newly minted tokens. |
amount | BigNumberish | The quantity of tokens to be created. This value is denoted in the minutest unit of the token, such as Wei for Ether, and can be provided as a number, string, or BigNumber. |
signer | WalletSigner | The wallet signer instance tasked with endorsing the minting transaction. This signer usually symbolizes an address with minting authorizations in the token contract. It is frequently instantiated using the createWalletSigner function of EdexaClient . |
Returns
- A
Promise
that culminates in aTransactionResponse
object. This entity offers insights into the minting transaction, like its standing, transaction hash, among other details.
Usage Example
Start by creating an instance of the desired ERC20 token contract:
const erc20 = edexaClient.getERC20Instance("0x4DB67190e915C15aA8CCd889F35185D73dA37878");
Proceed to employ the mint
method to generate fresh tokens:
const recipientAddress = "0x2c360D20cE6b3D8b466511eF093C9177c3817B94";
const mintAmount = "2000000000000000000"; // Symbolizing 2 tokens, given 18 decimals are in play
const signer = edexaClient.createWalletSigner("private key imbued with minting rights");
const transactionResponse = await erc20.mint(recipientAddress, mintAmount, signer);
console.log(`Transaction Hash: ${transactionResponse.hash}`);
Notes
Ensure the signer's address is vested with the requisite permissions within the token contract to initiate a minting procedure.
The minting
amount
should be designated in the token's tiniest divisible unit. Always verify the conversions prior to determining the minting sum.Exercise extreme prudence when managing your private keys. When deploying the
signer
, ensure its protection to preclude the exposure of private keys in vulnerable settings.