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 chainId = 84532;
const contractAddress = "0xcB30dB8FB977e8b27ae34c86aF16C4F5E428c0bE";
const addresses = [
  {
    address: "0x1f91EB653116A43413930c1df0CF5794fCc2D611",
    quantity: "1",
  },
  {
    address: "0xA707E9650631800a635c629e9C8E5937b7277a08",
    quantity: "1",
  },
  {
    address: "0xF1f466c973C197e5D9318F6241C2da31742d3d03",
    quantity: "1",
  },
];

const url = `${YOUR_ENGINE_URL}/contract/${chainId}/${contractAddress}/erc1155/airdrop`;

const response = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_SECRET_TOKEN",
    "Content-Type": "application/json",
    "X-Backend-Wallet-Address": "YOUR_BACKEND_WALLET_ADDRESS",
  },
  body: JSON.stringify({ addresses }),
});

const data = await response.json();
const queueId = data.queueId;

Get Transaction Status

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

function getEngineTxStatus(queueId: string) {
  const url = `${YOUR_ENGINE_URL}/transaction/${queueId}`;
  const response = await fetch(url, {
    method: "GET",
    headers: {
      "Authorization": "Bearer YOUR_SECRET_TOKEN",
    },
  });

  const data = await response.json();
  return data.result;
}

// you can keep polling for the status until you get a status of either "mined" or "errored" or "cancelled"
const result = await getEngineTxStatus(queueId);

console.log(result.status);