npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gelatonetwork/automate-sdk

v3.0.33

Published

SDK to create Automate tasks

Downloads

1,765

Readme

Gelato Automate SDK

Automate your smart contracts using Automate SDK

Installation

yarn add @gelatonetwork/automate-sdk

or

npm install @gelatonetwork/automate-sdk

How to use?

  1. Import the Automate SDK into your project:
import { AutomateSDK } from "@gelatonetwork/automate-sdk";
  1. Check if Automate is deployed on your network:
import { isAutomateSupported } from "@gelatonetwork/automate-sdk";

if (!isAutomateSupported(chainId)) {
  console.log(`Automate network not supported (${chainId})`);
  return;
}
  1. Instantiate Automate using your signer:
const automate = new AutomateSDK(chainId, signer);
  1. Create an automation task:
interface CreateTaskOptions {
  name: string; // your task name

  // Function to execute
  execAddress: string; // address of your target smart contract
  execSelector: string; // function selector to execute on your target smart contract
  execAbi?: string; // ABI of your target smart contract

  // Proxy caller
  dedicatedMsgSender: boolean; // task will be called via a dedicated msg.sender which you can whitelist (recommended: true)

  // Optional: Pre-defined / static target smart contract inputs
  execData?: string; // exec call data

  // Optional: Dynamic target smart contract inputs (using a resolver)
  resolverAddress?: string; // resolver contract address
  resolverData?: string; // resolver call data (encoded data with function selector)
  resolverAbi?: string; // your resolver smart contract ABI

  // Optional: Single execution task
  singleExec?: boolean; // task cancels itself after 1 execution if true.

  // Web3 function params
  web3FunctionHash?: string; // ipfs hash of your web3 function
  web3FunctionArgs?: { [key: string]: unknown }; // web3 function arguments object

  // Optional: Payment params
  useTreasury?: boolean; // use false if your task is self-paying (default: true)

  // Optional: Trigger params, 60s time interval trigger as default if undefined
  trigger?:
    | {
        type: TriggerType.TIME; // time interval trigger
        interval: number; // task interval in ms
        start?: number; // task start timestamp, task will start immediately if undefined or 0
      }
    | {
        type: TriggerType.CRON; // cron trigger
        cron: string; // cron expression
      };
    | {
        type: TriggerType.EVENT; // event trigger
        filter: {
          address: string; // address to listen events for
          topics: Array<Array<string | null>>; // topics to listen for check Ethers.js doc (https://docs.ethers.org/v5/concepts/events/#events--filters)
        };
        blockConfirmations: number; // number of blocks to confirm event before triggering
      };
    |
      {
        type: TriggerType.BLOCK; // block trigger
      };
}

const params: CreateTaskOptions = {
  name,
  execAddress,
  execSelector,
  interval,
  dedicatedMsgSender,
};
const { taskId, tx }: TaskTransaction = await automate.createTask(params);
await tx.wait(); // Optionally wait for tx confirmation
console.log(`Task created, taskId: ${taskId} (tx hash: ${tx.hash})`);
  1. Retrieve all your tasks:
const activeTasks = await automate.getActiveTasks();
activeTasks.forEach((task: Task) => {
  console.log(`- ${task.name} (${task.taskId})`);
});
  1. Rename a task:
await automate.renameTask(taskId, "Another Gelato name");
  1. Cancel a task:
const { taskId, tx }: TaskTransaction = await automate.cancelTask(taskId);
await tx.wait(); // Optionally wait for tx confirmation
console.log(`Task canceled, taskId: ${taskId} (tx hash: ${tx.hash})`);
  1. Overriding gas settings:

If you need to override gas settings, you can pass an additional Overrides object to createTask & cancelTask methods:

const params: CreateTaskOptions = {
  name,
  execAddress,
  execSelector,
  interval,
  dedicatedMsgSender,
};
const overrides: Overrides = { gasLimit: 2000000 };
const tx: TaskTransaction = await automate.createTask(params, overrides);
  1. Whitelisting msg.sender of function:

If you enabled dedicatedMsgSender, your task will be called via a dedicated msg.sender which you can whitelist on your smart contract for extra security.

If dedicatedMsgSender is set to false, msg.sender of the task will be the Automate contract.

To fetch your dedicated msg.sender:

const { address } = await automate.getDedicatedMsgSender();
console.log("Dedicated msg.sender: ", address);

Examples

Check out our tutorial repository automate-sdk-hello-world for more in-depth examples.