Sign In

@metamask/cronjob-example-snap

Package Overview
Dependencies
Maintainers
9
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metamask/cronjob-example-snap

MetaMask example snap demonstrating the use of cronjobs in snaps

latest
Source
npmnpm
Version
3.0.0
Version published
Weekly downloads
1.3K
-16.35%
Maintainers
9
Weekly downloads
 
Created
Source

@metamask/cronjob-example-snap

This snap demonstrates the use of the endowment:cronjob permission to periodically execute a function.

Snap manifest

Note: Using cronjobs in your snap requires theendowment:cronjob permissions. Refer to the documentation for more information.

Along with other permissions, the manifest of this snap includes the endowment:cronjob permission:

{
  "initialPermissions": {
    "endowment:cronjob": {
      "jobs": [
        {
          "expression": "* * * * *",
          "request": {
            "method": "execute"
          }
        }
      ]
    }
  }
}

A snap can schedule one or more cronjobs by specifying an array of jobs in the endowment:cronjob permission. Each job is defined by an expression and a request object. The expression is a cron expression that defines the schedule of the job. The request object defines the JSON-RPC request that will be sent to the snap's onCronjob handler when the job is executed.

In this example, we schedule a job that executes every minute. When the job is executed, the snap's onCronjob handler is called with the following JSON-RPC request:

{
  "method": "execute"
}

For more information, you can refer to the end-to-end tests.

Keywords

MetaMask

FAQs

Package last updated on 15 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts