< BACK

Automated reward claiming

This project showcases general-purpose examples of automating smart contracts with gelato as well as the application for superfluid streams presenting a very simple 3+3 Step guide to create programmable cash flows.

Step 1: Wire Gelato infrastructure

In order to interact with the gelato network, we will need to interact with the Gelato contracts (addresses can be found here). We will interact with three contracts:

Ops Contract: The main contract for creating, canceling, getting transaction Fees, transfer fees, etc. We will inherit the contract OpsReady.sol , we will pass in the constructor the gelato ops and gelato treasury addresses and we are good to go!.

import GelatoRelaySDK from "@gelatonetwork/relay-sdk";

const paymentMethod = GelatoRelaySDK.PaymentType.OneBalance;

// set up on-chain variables
const counter = "0x2FA3fDDEd0eb4c24e8B7FB1fF756a3aeCFFA85DF"; // Goerli
const account = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"; // vitalik.eth
const abi = ["function incrementCounter()"];

// generate payload
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();

const contract = new ethers.Contract(counterAddress, abi, signer);
const { data } = await contract.populateTransaction.incrementCounter();

// populate relay request
const relayRequest = {
  chainId: provider.network.chainId,
  target: counter,
  data: data,
  user: signer.getAddress(),
  oneBalanceChainId: provider.network.chainId,
};

// send relayRequest to Gelato Relay API
const relayResponse =
  await GelatoRelaySDK.relayWithUserSignature(
    paymentMethod,
    relayRequest,
    provider
);

Step 2: Gelato Funding Strategy

Gelato executes transactions at a future point in time, therefore we need to choose a way of funding the transactions that Gelato is going to execute on our behalf. There are two alternatives to do that:

1) Fund the Gelato Treasury Contract: as long as you have a positive balance in the treasury contract, the future transactions will be executed. If we choose this alternative we need to interact with the Gelato Treasury Contract funding it.

import GelatoRelaySDK from "@gelatonetwork/relay-sdk";

const paymentMethod = GelatoRelaySDK.PaymentType.OneBalance;

// set up on-chain variables
const counter = "0x2FA3fDDEd0eb4c24e8B7FB1fF756a3aeCFFA85DF"; // Goerli
const account = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"; // vitalik.eth
const abi = ["function incrementCounter()"];

// generate payload
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();

2) Fund every transaction: Our smart contract will transfer in every future transaction the amount requested to pay the fees. In this case, we won’t need to interact with the Gelato Treasury Contract but we must maintain a positive balance in our contract.

Step 3: Gelato Business Logic

There are three main parts/steps that we have to define within the business logic: 3.1) Create the Task: We will have to define a task to tell Gelato what we want to be executed.

Ops Contract: The main contract for creating, canceling, getting transaction Fees, transfer fees, etc. We will inherit the contract OpsReady.sol , we will pass in the constructor the gelato ops and gelato treasury addresses and we are good to go!.

Live users
Yearn

Yearn

Explore

Use Cases

Bridge
Gasless Cross-Chain Asset Bridging
Connext
Nomad
Hyperlane
Kinetex
NFT
NFT Limit Orders
NFTrade
Social Media
Gasless Social Media Experience
Koru DAO
Gaming
Gasless Minting of NFTs
Flair