Skip to main content

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.

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

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

Usage

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

// Your smart contract address
const contractAddress = "{{contract_address}}";

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

Configuration

addresses

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.