Fetch Controller
Now that you've successfully initialized your Controller, let's learn how to fetch and inspect its on-chain data. This is essential for verifying state changes, building UIs, or checking protocol compliance.
Basic Fetch Example
import { fetchController } from "@dropsy/airdrop";
async function getController(controllerPda: Address) {
const controller = await fetchController(client.rpc, controllerPda);
if (!controller.exists) {
throw new Error("Controller not found");
}
console.log("Authority:", controller.data.authority);
console.log("Current fee:", controller.data.feeLamports);
return controller;
}
This returns the full account info including decoded data structure.
Response Structure
{
// Account metadata
executable: false,
lamports: 1468560n, // Account balance
programAddress: 'Dropm...',
space: 83n, // Allocated bytes
address: '2qJk...', // Controller PDA
// Decoded data
data: {
authority: 'CeN4...', // Owner wallet
feeVault: 'BtjQ...', // Fee collection address
feeLamports: 5000n, // Current protocol fee
version: 0, // Protocol version
bump: 254, // PDA derivation seed
feeVaultBump: 254 // Fee vault seed
},
exists: true // Account existence flag
}
Common Use Cases
- Pre-initialization check: Verify if a controller already exists
- Fee monitoring: Track collected fees in the vault
- Authority verification: Confirm controller ownership
- Protocol upgrades: Check version compatibility
💡 Pro Tip: Combine this with your initialization logic to create safe initialization flows that check for existing controllers first.