Skip to main content

useClaimToken

Hook for claiming a token from a smart contract.

Available to use on smart contracts that implement the ERC20 or ERC721 standard.

import { useClaimToken } from "@thirdweb-dev/react";

Usage

Provide your token contract as the argument.

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);

if (error) {
console.error("failed to claim token", error);
}

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

to

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

You can use the useAddress hook to get this value.

import {
useClaimToken,
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: claimToken, isLoading, error } = useClaimToken(contract);

if (error) {
console.error("failed to claim token", error);
}

return (
<Web3Button
contractAddress={contractAddress}
action={() =>
claimToken({
to: address, // Use useAddress hook to get current wallet address
amount: 100, // Amount of token to claim
})
}
>
Claim Token
</Web3Button>
);
}

amount

The amount of token to be claimed.

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);

if (error) {
console.error("failed to claim token", error);
}

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>
);
}