useBurnToken
Hook for burning ERC20 tokens on a smart contract.
Available to use on smart contracts that implement the ERC20 standard.
import { useBurnToken } from "@thirdweb-dev/react";
Usage
Provide your token contract as the argument.
import { useBurnToken, useContract, Web3Button } from "@thirdweb-dev/react";
// Your smart contract address
const contractAddress = "{{contract_address}}";
function App() {
const { contract } = useContract(contractAddress);
const { mutateAsync: burnToken, isLoading, error } = useBurnToken(contract);
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
burnToken({
to: "{{wallet_address}}",
amount: "10", // Amount of tokens to burn
})
}
>
Burn Token
</Web3Button>
);
}
Configuration
to
Likely, you will want to burn the token from the currently connected wallet address.
You can use the useAddress
hook to get this value.
import {
useBurnToken,
useContract,
Web3Button,
useAddress,
} from "@thirdweb-dev/react";
// Your smart contract address
const contractAddress = "{{contract_address}}";
function App() {
const address = useAddress();
const { contract } = useContract(contractAddress);
const { mutateAsync: burnToken, isLoading, error } = useBurnToken(contract);
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
burnToken({
to: address,
amount: "10", // Amount of tokens to burn
})
}
>
Burn Token
</Web3Button>
);
}
amount
The amount of tokens to burn.
import { useBurnToken, useContract, Web3Button } from "@thirdweb-dev/react";
// Your smart contract address
const contractAddress = "{{contract_address}}";
function App() {
const { contract } = useContract(contractAddress);
const { mutateAsync: burnToken, isLoading, error } = useBurnToken(contract);
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
burnToken({
to: "{{wallet_address}}",
amount: "10", // Amount of tokens to burn
})
}
>
Burn Token
</Web3Button>
);
}