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.

Example

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>
);
}
function useMintToken(
contract: RequiredParam<TokenContract>,
): UseMutationResult<
Omit<
{
data: () => Promise<unknown>;
receipt: providers.TransactionReceipt;
},
"data"
>,
unknown,
unknown
>;

Parameters

Instance of a TokenContract

Type

let contract: RequiredParam<TokenContract>;

Returns

let returnType: UseMutationResult<
Omit<
{
data: () => Promise<unknown>;
receipt: providers.TransactionReceipt;
},
"data"
>,
unknown,
unknown
>;

A mutation object to mint new tokens to the connected wallet

const { mutateAsync, isLoading, error } = useMintToken(contract);

options

The mutation function takes an object as an argument with the following properties:

amount

The quantity of tokens to mint. Can be a string or number .

to

The wallet address to mint the new tokens to.

To use the connected wallet address, use the useAddress hook.