useClaimToken
Hook for claiming a ERC20 tokens from a smart contract.
Available to use on smart contracts that implement both the ERC20 interface
and the claim
function,
such as the Token Drop.
import { useClaimToken } from "@thirdweb-dev/react";
const { mutateAsync, isLoading, error } = useClaimToken(contract);
Usage
Provide your token contract as the argument to the hook.
import { useClaimToken, useContract, Web3Button } from "@thirdweb-dev/react";
// Your smart contract address
const contractAddress = "{{contract_address}}";
function App() {
const { contract } = useContract(contractAddress);
const { mutateAsync: claimToken, isLoading, error } = useClaimToken(contract);
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
claimToken({
to: "{{wallet_address}}", // Use useAddress hook to get current wallet address
amount: 100, // Amount of token to claim
})
}
>
Claim Token
</Web3Button>
);
}