Docs

useTransferBatchToken

Hook for transferring ERC20 tokens to multiple recipients in a single transaction (i.e. airdrop).

Available to use on contracts that implement the ERC20 interface.

The wallet that initiates this transaction must have sufficient balance to cover the total amount of tokens being transferred and must have transfer permissions on the contract, i.e. tokens are not soulbound.

Example

Provide your token contract instance from the useContract hook to the hook.

Then, provide an array of objects with the to and amount properties to the function.

import {
useTransferBatchToken,
useContract,
Web3Button,
} from "@thirdweb-dev/react";
function App() {
const { contract } = useContract(contractAddress, "token");
const {
mutateAsync: transferBatchToken,
isLoading,
error,
} = useTransferBatchToken(contract);
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
transferBatchToken([
{
to: "{{wallet_address}}", // Transfer 10 tokens to a wallet
amount: 10,
},
{
to: "{{wallet_address}}", // Transfer 20 tokens to another wallet
amount: 20,
},
])
}
>
Transfer Batch Tokens
</Web3Button>
);
}

Parameters

Returns

A Mutation object to transfer batch tokens

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

options

The mutation function takes an array of objects containing to and amount properties.

  • to - The wallet address to transfer tokens to. Must be a string .

  • amount - The amount of tokens to transfer. Must be a number .