Ensuring Data Continuity for Your Web3 App with API3 & Gelato

Gelato Team

Jun 28, 2023

The classic oracle problem in blockchain revolves around how protocols can reliably ingest off-chain data. Since Web3 apps and smart contracts are automatic and interconnected, corrupt or invalid data ingestions can create severe consequences for users.

API3 addresses this by promoting “decentralized APIs” (dAPIs), where first-party providers run their own oracle and write data directly on-chain. These dAPIs are governed by the API3 DAO.

Self-Funded dAPIs

Self-Funded dAPIs allow developers to use data feeds permissionlessly with minimal upfront commitment. You fund the dAPI yourself, and the amount of gas supplied determines how long it stays live.

Funds are used by the oracle supporting the feed to pay gas when placing values on-chain.

Gelato Automate for Business Continuity

Gelato Automate provides decentralized smart contract automation, enabling recurring actions when conditions are met.

For Self-Funded dAPIs, Gelato Automate ensures business continuity by automatically topping up funds to avoid downtime and data interruptions.

A detailed implementation guide is available in API3 docs: Automate funding of multiple Self-Funded dAPIs with Gelato.

Code Example

The following function checkSponsorWallet automates the process of topping up sponsor wallets:

function checkSponsorWallet() external view returns (bool canExec, bytes memory execPayload) {
    uint unfunded = 0;
    canExec = false;

    // Step 1: Count unfunded sponsor wallets
    for (uint i = 0; i < sponsorWallets.length; i++) {
        if (sponsorWallets[i].balance < minimumBalance) {
            unfunded++;
        }
    }

    // Step 2: Create array of unfunded wallets
    address[] memory unfundedSponsorWallets = new address[](unfunded);
    uint counter = 0;
    for (uint j = 0; j < sponsorWallets.length; j++) {
        if (sponsorWallets[j].balance < minimumBalance) {
            unfundedSponsorWallets[counter] = sponsorWallets[j];
            counter++;
        }
    }

    // Step 3: Build payload to fund wallets
    execPayload = abi.encodeWithSignature(
        "fundSponsorWallet(address[],uint256)", 
        unfundedSponsorWallets, 
        fundAmount
    );

    if (unfundedSponsorWallets.length > 0) {
        canExec = true;
    }
}

Steps Explained:

  1. Count sponsor wallets below minimumBalance.

  2. Build an array of unfunded sponsor wallets.

  3. Prepare an execPayload transaction to fund those wallets and mark the task executable.

With just these lines of Solidity, you can auto top-up Self-Funded dAPIs and ensure uninterrupted, high-quality data feeds using API3 and Gelato Automate.

Conclusion

By combining API3 and Gelato Automate, developers can reliably maintain oracle feeds, improve trust in their applications, and contribute to a more secure and efficient blockchain ecosystem.

👉 Join our developer community on Discord.

Ready to build?

Start with a testnet, launch your mainnet in days, and scale with industry-leading UX.

Ready to build?

Start with a testnet, launch your mainnet in days, and scale with industry-leading UX.

Ready to build?

Start with a testnet, launch your mainnet in days, and scale with industry-leading UX.

Ready to build?

Start with a testnet, launch your mainnet in days, and scale with industry-leading UX.