Create a rule
Every trigger, action and option of a rule, with the checks the SDK runs before it spends a transaction.
A rule is one call. The SDK validates it, checks the target exists, and writes one entity.
const { key, txHash, warnings } = await triggers.createRule({
name: 'Lease reminder',
trigger: { on: 'expire', target: leaseKey, offset: 1800n },
action: 'webhook',
url: 'https://example.com/hooks/arkiv',
message: '{rule}: {entity} expires at {time}',
})Triggers
trigger: { on: 'expire', target: '0x…', offset: 1800n }target is an entity key (0x and 64 hex characters). The rule fires when that entity expires, or
offset blocks earlier. The deadline follows the target: if someone extends the target, the rule
fires later. If the target is deleted before it expires, the worker records a skipped receipt
instead of firing.
The SDK reads the target before writing the rule, and throws TriggersError if it has already
expired, been deleted, or never existed.
Offsets are blocks, as bigint: 15 minutes is 450n, 1 hour 1800n, 1 day 43200n.
Actions
action | Needs | What the worker does |
|---|---|---|
telegram | message, chat (sealed), worker | Sends the message from the OpenTrigger bot. See Telegram |
webhook | url (https://), optional message | A signed POST. See Webhooks |
receipt | nothing | Writes the receipt and nothing else |
extend | extendDays | Extends the expire target. See Keep data alive |
message may use {entity}, {time} and {rule}; the worker fills them in when it fires.
Options
Prop
Type
Checks before the transaction
validateRule(input)throwsSchemaErrorwith a readable message: a bad entity key, anhttp://URL, a Telegram rule with a plain chat ID,retriesout of range, and so on.createRuleruns it for you.ruleWarnings(input)returns strings that do not block publishing, for example a webhook URL that looks like it contains a secret.createRulereturns them aswarnings.
Rules are public
Anyone can read a rule. Never put a secret, an API key or personal data in name, message or
url. A Slack or Discord webhook URL is a secret.
Several rules in one transaction
const { keys } = await triggers.createRules([ruleA, ruleB])They all land or none does. The dashboard uses this when one trigger has two actions.
Delete a rule
await triggers.deleteRule(key)A deleted rule never fires. Receipts already written stay, and the rule's history remains in the chain.
How long a rule lives
A rule expires a week after its deadline (at least one day), so it cleans itself up and its receipts stay readable next to it for that week. See Entities.