Playground

Airdrop

Engine makes it effortless for any developer to airdrop tokens at scale. You sponsor the gas so your users only need a wallet address!

Example

Airdrop tokens to multiple addresses in a single transaction using thirdweb Engine

Details

Recipients (3)

  • 0x1f91EB653116A43413930c1df0CF5794fCc2D611
  • 0xA707E9650631800a635c629e9C8E5937b7277a08
  • 0xF1f466c973C197e5D9318F6241C2da31742d3d03

Each address will receive 1 token

Preview
Airdrop

Start the airdrop to distribute tokens to recipients

Code

Code to implement above shown example

Send Airdrop Transaction Request

const addresses = [
  {
    recipient: "0x1f91EB653116A43413930c1df0CF5794fCc2D611",
    amount: "1",
  },
  {
    recipient: "0xA707E9650631800a635c629e9C8E5937b7277a08",
    amount: "1",
  },
  {
    recipient: "0xF1f466c973C197e5D9318F6241C2da31742d3d03",
    amount: "1",
  },
];

const contract = getContract({
  address: 0x6e238275023a2575136cf60f655b6b2c0c58b4ac,
  chain: defineChain(84532),
  client: THIRDWEB_CLIENT,
});

const transaction = airdropERC20({
  contract,
  tokenAddress: 0x6e238275023a2575136cf60f655b6b2c0c58b4ac,
  contents: addresses,
});

const serverWallet = Engine.serverWallet({
  address: BACKEND_WALLET_ADDRESS,
  client: THIRDWEB_CLIENT,
  vaultAccessToken: ENGINE_VAULT_ACCESS_TOKEN,
});

const { transactionId } = await serverWallet.enqueueTransaction({
  transaction,
});

Get Transaction Status

Once you send a request to airdrop tokens, you can poll for the status of the transaction using the following code.

const result = await Engine.getTransactionStatus({
  client: THIRDWEB_CLIENT,
  transactionId: transactionId,
});

console.log(result.status);

// or wait for the transaction to be mined (polls status until it's mined)
const result = await Engine.waitForTransactionHash({
  client: THIRDWEB_CLIENT,
  transactionId: transactionId,
});

console.log(result.transactionHash);