snap_scheduleBackgroundEvent
Description
Schedule a background event for a Snap. The background event will trigger a
JSON-RPC request to the Snap at the scheduled time, handled by the
onCronjob entry point in the Snap.
The schedule can be defined using either an ISO 8601 date or duration string. For example:
- Using a date:
2026-12-31T23:59:59Z - Using a duration:
P1DT2H(which represents a duration of 1 day and 2 hours)
Parameters
An object containing the parameters for the snap_scheduleBackgroundEvent
method.
Options
date
stringThe ISO 8601 date string of when to fire the background event (e.g.,
"2025-01-01T00:00:00Z").
or
duration
stringThe ISO 8601 duration string of how long to wait before firing the
background event (e.g., "P1D" for one day). The resulting date will
be calculated in UTC.
Common properties
request
objectThe JSON-RPC request to call when the event fires.
method
stringThe method to call. This can be an arbitrary method, and is provided to
the onCronjob handler for the Snap to determine how to handle the
request.
params
JsonRpcParamsThe parameters to pass to the method. This can be used to provide
additional information about the request, and is provided to the
onCronjob handler for the Snap to determine how to handle the request.
Returns
The ID of the scheduled background event.
Example
const id = await wallet.request({
method: "snap_scheduleBackgroundEvent",
params: {
date: "2026-12-31T23:59:59Z",
request: {
method: "mySnapMethod",
params: { foo: "bar" },
},
},
});