|
| 1 | +import { Step, Steps, createMetadata } from "@doc"; |
| 2 | + |
| 3 | +export const metadata = createMetadata({ |
| 4 | + title: "Stylus Airdrop Contracts | thirdweb Documentation", |
| 5 | + description: |
| 6 | + "Use Stylus Airdrop contracts on Arbitrum for efficient token distribution at scale. WASM-powered smart contracts enable fast, low-cost airdrops to thousands of wallets.", |
| 7 | + image: { |
| 8 | + title: "Stylus Airdrop Contract", |
| 9 | + icon: "contracts", |
| 10 | + }, |
| 11 | +}); |
| 12 | + |
| 13 | +# Stylus Airdrop Contract |
| 14 | + |
| 15 | + |
| 16 | +If you need to send tokens to thousands of wallets at once, you can leverage the Stylus Airdrop contracts. |
| 17 | + |
| 18 | +Learn how to deploy Stylus Airdrop contracts through dashboard or CLI for inexpensive, WASM-powered distribution on [Arbitrum](https://thirdweb.com/arbitrum) chain. |
| 19 | + |
| 20 | +### Benefits |
| 21 | + |
| 22 | +- Ink, not gas: Stylus executes WASM thousands of times faster than the EVM, so sending 10 000 NFTs costs a fraction of normal gas. |
| 23 | +- Rust Tooling: Cargo tests, Clippy lints, and the full crates ecosystem for your drop logic. |
| 24 | +- Interoperability: Rust contracts call Solidity (and vice-versa) with zero wrappers. |
| 25 | +- Battle-tested Logic: Template ports the same claim, snapshot & signature pattern used by thirdweb’s Solidity pre-built contracts. |
| 26 | + |
| 27 | +## Deploy through dashboard |
| 28 | + |
| 29 | +Deploying a Stylus Airdrop contract is easy through the thirdweb dashboard and ideal when you don't want to modify any code on the contract. |
| 30 | + |
| 31 | +<Steps> |
| 32 | +<Step title="Select Stylus Contract"> |
| 33 | + |
| 34 | +Navigate to the Stylus Contracts section on Explore and select any Airdrop contract for your project. |
| 35 | +</Step> |
| 36 | + |
| 37 | +<Step title="Deploy Contract"> |
| 38 | +Select Arbitrum Sepolia or any other Stylus-supported network, then select Deploy. |
| 39 | +</Step> |
| 40 | + |
| 41 | +<Step title="Upload Recipients"> |
| 42 | +You can either upload a CSV file with the recipient addresses and amounts and select `Run Airdrop` |
| 43 | + |
| 44 | +Or set a claim condition for recipients to claim their tokens on their own. |
| 45 | +</Step> |
| 46 | + |
| 47 | +</Steps> |
| 48 | + |
| 49 | +## Deploy through CLI |
| 50 | + |
| 51 | +If you want to modify the contract code or deploy a custom Airdrop contract, you can use the thirdweb CLI. |
| 52 | + |
| 53 | +<Steps> |
| 54 | +<Step title="Create a new Stylus Airdrop project"> |
| 55 | + |
| 56 | +In your CLI, run the following command to create a new directory with an airdrop template contract. |
| 57 | + |
| 58 | +```bash |
| 59 | +npx thirdweb create-stylus --template airdrop-erc721 |
| 60 | +``` |
| 61 | +</Step> |
| 62 | + |
| 63 | +<Step title="Modify contract logic"> |
| 64 | +In the `src/lib.rs` file you can modify the contract logic such as adding fees, gating logic, analytics events, and more. |
| 65 | +</Step> |
| 66 | + |
| 67 | +<Step title="Build & Test the Contract"> |
| 68 | + |
| 69 | +To build your project, run the following command: |
| 70 | + |
| 71 | +```bash |
| 72 | +cargo stylus build |
| 73 | +``` |
| 74 | + |
| 75 | +</Step> |
| 76 | + |
| 77 | +<Step title="Deploy or Publish Your Contract"> |
| 78 | +You can publish and deploy your project to Arbitrum. Publishing stores your contract metadata in thirdweb’s on-chain registry so anyone (including you) can deploy that exact version later with a few clicks. |
| 79 | + |
| 80 | +To publish your contract, ensure you have your thirdweb secret key from your created project, then run the following command: |
| 81 | + |
| 82 | +```bash |
| 83 | +npx thirdweb publish-stylus -k YOUR_TW_SECRET_KEY |
| 84 | +``` |
| 85 | + |
| 86 | +If you'd prefer to just deploy a single instance of the contract without publishing, run the following command to deploy: |
| 87 | + |
| 88 | +```bash |
| 89 | +npx thirdweb deploy-stylus -k YOUR_TW_SECRET_KEY |
| 90 | +``` |
| 91 | + |
| 92 | +Once the transaction confirms, the CLI will redirect you to the contract management dashboard where you can mint, transfer, view events, or pull ready-made SDK snippets. |
| 93 | +</Step> |
| 94 | + |
| 95 | +</Steps> |
| 96 | + |
| 97 | +## Interacting with the Contract |
| 98 | + |
| 99 | +Using the thirdweb SDKs, you can interact with your Stylus Airdrop contract to mint tokens, transfer ownership, and more. |
| 100 | + |
| 101 | +The following includes three common patterns using thirdweb TypeScript SDK: |
| 102 | + |
| 103 | +### Owner-executed batch airdrop |
| 104 | + |
| 105 | +**When to use:** you already have every recipient’s address and want to send everything in a single transaction. |
| 106 | + |
| 107 | +```javascript |
| 108 | +import { createThirdwebClient, getContract, sendTransaction} from "thirdweb"; |
| 109 | +import { arbitrumSepolia } from "thirdweb/chains"; |
| 110 | +import { airdropERC721 } from "thirdweb/extensions/airdrop"; |
| 111 | +import { createWallet, injectedProvider } from "thirdweb/wallets"; |
| 112 | + |
| 113 | +const client = createThirdwebClient({ clientId }); |
| 114 | + |
| 115 | +const wallet = createWallet("io.metamask"); // or any wallet id |
| 116 | +const account = await wallet.connect({ client }); |
| 117 | + |
| 118 | +const contract = getContract({ |
| 119 | + client, |
| 120 | + chain: arbitrumSepolia, |
| 121 | + address: "<DEPLOYED_ADDRESS>", |
| 122 | +}); |
| 123 | + |
| 124 | +const contents = [ |
| 125 | + { recipient: "0xAbc…", tokenId: 1n }, |
| 126 | + { recipient: "0x123…", tokenId: 2n }, |
| 127 | +]; |
| 128 | + |
| 129 | +const tx = airdropERC721({ |
| 130 | + contract, |
| 131 | + tokenAddress: contract.address, |
| 132 | + contents, |
| 133 | +}); |
| 134 | + |
| 135 | +await sendTransaction({ transaction: tx, account }); |
| 136 | +``` |
| 137 | + |
| 138 | +(Swap for airdropERC20 or airdropERC1155 helpers as needed.) |
| 139 | + |
| 140 | +### Claim-based airdrop (Merkle snapshot) |
| 141 | + |
| 142 | +**When to use:** you know the recipients but want them to claim the tokens at their convenience (gas paid by the claimer). |
| 143 | + |
| 144 | +1. Generate snapshot off-chain |
| 145 | + |
| 146 | +```javascript |
| 147 | +import { generateMerkleTreeInfoERC721 } from "thirdweb/extensions/airdrop"; |
| 148 | + |
| 149 | +const snapshot = [ |
| 150 | + { address: "0xAbc…", tokenId: 7n }, |
| 151 | + { address: "0x123…", tokenId: 8n }, |
| 152 | +]; |
| 153 | + |
| 154 | +const { merkleRoot, contents } = await generateMerkleTreeInfoERC721({ snapshot }); |
| 155 | +``` |
| 156 | + |
| 157 | +merkleRoot is a single 32-byte value representing the whole list. |
| 158 | + |
| 159 | +2. Store root on-chain (_setMerkleRoot(root) in the template). |
| 160 | + |
| 161 | +```javascript |
| 162 | +const tx = setMerkleRoot({ |
| 163 | + contract, |
| 164 | + root: merkleRoot, |
| 165 | +}); |
| 166 | +await sendTransaction({ transaction: tx, account }); // executed by admin |
| 167 | +``` |
| 168 | + |
| 169 | +3. Recipient claims: |
| 170 | + |
| 171 | +```javascript |
| 172 | +import { claimERC721, fetchProofsERC721 } from "thirdweb/extensions/airdrop"; |
| 173 | + |
| 174 | +const proof = await fetchProofsERC721({ |
| 175 | + contract, |
| 176 | + merkleRoot, |
| 177 | + recipient: "0xAbc…", |
| 178 | +}); |
| 179 | + |
| 180 | +const tx = claimERC721({ |
| 181 | + contract, |
| 182 | + tokenAddress: contract.address, |
| 183 | + proof, |
| 184 | +}); |
| 185 | + |
| 186 | +await sendTransaction({ transaction: tx, account }); |
| 187 | +``` |
| 188 | + |
| 189 | +### Signature Based Airdrop (Dynamic Authentication) |
| 190 | + |
| 191 | +**When to use:** you don’t know the full list ahead of time (e.g., quest rewards). An authorised backend signs a payload per user; the user submits it on-chain. |
| 192 | + |
| 193 | +1. Generate signed payload server-side: |
| 194 | + |
| 195 | +```javascript |
| 196 | +import { generateAirdropSignatureERC721 } from "thirdweb/extensions/airdrop"; |
| 197 | + |
| 198 | +const { signature, payload } = await generateAirdropSignatureERC721({ |
| 199 | + contract, |
| 200 | + signer: account, // ADMIN role or owner |
| 201 | + to: "0xRecipient", |
| 202 | + tokenId: 42n, |
| 203 | +}); |
| 204 | +``` |
| 205 | + |
| 206 | +2. Recipient executes: |
| 207 | + |
| 208 | +```javascript |
| 209 | +import { airdropERC721WithSignature } from "thirdweb/extensions/airdrop"; |
| 210 | + |
| 211 | +const tx = airdropERC721WithSignature({ |
| 212 | + contract, |
| 213 | + signature, |
| 214 | + payload, |
| 215 | +}); |
| 216 | + |
| 217 | +await sendTransaction({ transaction: tx, account: recipientAccount }); |
| 218 | +``` |
| 219 | + |
| 220 | +### Resources |
| 221 | + |
| 222 | +- [ERC-721 Airdrop Template](https://github.com/thirdweb-example/stylus-airdrop-erc721-template) |
| 223 | +- [TypeScript SDK Documentation > Airdrops](https://portal.thirdweb.com/references/typescript/v5/airdrop/airdropERC721) |
| 224 | + |
0 commit comments