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>
);
}
Configuration
amount (required)
amount (required)
The quantity of tokens to mint. Can be a string
or number
.
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);
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>
);
}
to (required)
to (required)
The wallet address to mint the new tokens to.
To use the connected wallet address, use the useAddress
hook.
import {
useContract,
useMintToken,
Web3Button,
useAddress,
} from "@thirdweb-dev/react";
const contractAddress = "{{contract_address}}";
const tokenAmount = "{{token_amount}}";
function App() {
// Contract must be an ERC-20 contract that implements the ERC20Mintable interface
const { contract } = useContract(contractAddress);
const { mutateAsync: mintToken, isLoading, error } = useMintToken(contract);
const address = useAddress();
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
mintToken({
amount: tokenAmount, // Quantity to mint
to: address, // Address to mint to
})
}
>
Mint Token
</Web3Button>
);
}