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 .

Example

import {
useClaimToken,
useContract,
Web3Button,
} from "@thirdweb-dev/react";
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>
);
}

Parameters

Returns

A mutation object to tokens to the wallet specified in the params

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

options

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

to (required)

Likely, you will want to claim the token to the currently connected wallet address.

You can use the useAddress hook to get this value.

amount (required)

The amount of tokens to be claimed.

checkERC20Allowance (optional)

Boolean value to check whether the current wallet has enough allowance to pay for claiming the tokens before attempting to claim the tokens.

Defaults to true .