useMintToken
Hook for minting new tokens in an ERC20 smart contract.
Available to use on contracts that implement the ERC20Mintable interface, such as the Token contract.
The wallet address that initiates this transaction must have minting permissions on the contract.
import { useMintToken } from "@thirdweb-dev/react";
const { mutateAsync, isLoading, error } = useMintToken(contract);
Usage
Provide your ER20 contract as an argument to the hook.
import { useContract, useMintToken, Web3Button } from "@thirdweb-dev/react";
const contractAddress = "{{contract_address}}";
const walletAddress = "{{wallet_address}}";
const tokenAmount = "{{token_amount}}";
function App() {
// Contract must be an ERC-20 contract that implements the ERC20Mintable interface
const { contract } = useContract(contractAddress, "token");
const { mutateAsync: mintToken, isLoading, error } = useMintToken(contract);
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
mintToken({
amount: tokenAmount, // Quantity to mint
to: walletAddress, // Address to mint to
})
}
>
Mint Token
</Web3Button>
);
}