All triggers must be set during registration. A lambda may register multiple triggers.
module.exports.register=function(engine) {// register all triggers hereengine.onInterval(...);engine.onCron(...);engine.onEvent(...);engine.onBlocks(...);}
Concurrency
There are dozens of independent validators that execute lambdas on Orbs Network. By default, every time the trigger condition takes place, a single validator from the group will be selected to execute the lambda (this is handled automatically by the protocol).
If you want multiple validators to execute the trigger concurrently (in order to implement some custom consensus behavior), this can be specified in most triggers under the concurrency argument.
Trigger on interval
Execute a lambda function repeatedly every interval of time. For example once a day. There are no guarantees when exactly the function will run, meaning a lambda function that runs daily may trigger at any specific hour during the day. The function will run at least once in the requested interval, but in rare cases may also trigger more than once during the interval.
Interval string format: [integer]m|h|d
Examples: "10m" - every 10 minutes, "6h" - every 6 hours, "30d" - every 30 days
engine.onInterval(handler, { interval,// required string - [integer]m|h|d per format above network,// optional string - Network ID per supported networks concurrency,// optional string - "single" for single node (default), "multiple" for multiple nodes});
// run every 10 minutes on Ethereum mainnetengine.onInterval(handler, { interval:"10m", network:"ethereum" });
Trigger on cron
Execute a lambda in a predefined schedule according to a standard cron expression.
Cron string format: the standard format as explained here
Example: "42 * * * *" - run every hour when the minute is 42 (19:42, 20:42, etc)
Example: "0 0 * * 1" - run at 00:00 every Monday
engine.onCron(handler, { cron,// required string - standard cron format network,// optional string - Network ID per supported networks concurrency,// optional string - "single" for single node (default), "multiple" for multiple nodes});
// run every Monday at midnight (00:00) on Polygon mainnetengine.onCron(handler, { cron:"0 0 * * 1", network:"polygon" });
Trigger on contract event
Execute a lambda every time a specific smart contract emits a new event on-chain. The lambda will only be triggered for new events, meaning past events emitted before the lambda was deployed will not trigger execution. If multiple events were emitted, the lambda will be called separately for each one.
Some arguments, such as the optional filter and the resulting event passed to the handler, are compatible with the getPastEvents method in web3.
engine.onEvent(handler, { network,// required string - Network ID per supported networks contractAddress,// required string - smart contract address starting with "0x" abi,// required array - ABI interface of the smart contract eventName,// required string - the event name in ABI filter,// optional object - as in getPastEvents() web3.js method concurrency,// optional string - "single" for single node (default), "multiple" for multiple nodes});
asyncfunctionhandler(args) {args.web3 // initialized web3 object according to the networkargs.event // the actual event as in getPastEvents() web3.js method return valueargs.guardians /* key-value object of Guardians data: { "NEOPLY": { "weight": 279476867, "nodeAddress": "0xf8cd99a88707c4fc64ac91f237af8570a83cc018", "guardianAddress": "0x9520f53fd81c668e8088ae194c40e3f977b73d28", "ip": "54.95.108.148", "currentNode": true }, "오뽀가디언 - WhaleCoreStake - ORBS KOREA - ": { "weight": 134901962, "nodeAddress": "0x8cd2a24f0c3f50bce2f12c846277491433b47ae0", "guardianAddress": "0xc5e624d6824e626a6f14457810e794e4603cfee2", "ip": "34.227.204.75", "currentNode": false }, }....*/}
Example
// run every time there's a swap in the Uniswap V2 pair for ORBS-ETHconst abi = [{"name":"Swap","type":"event","anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0In","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1In","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount0Out","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1Out","type":"uint256"},{"indexed":true,"internalType":"address","name":"to","type":"address"}]}];
engine.onEvent(handler, { network: "ethereum", contractAddress: "0xC98B3B8C7CC0D7D925d1a407347b845D9F001391", abi, eventName: "Swap" });
Trigger on blocks
Execute a lambda every time new blocks are created on-chain. The lambda will only be triggered for new blocks, meaning past blocks created before the lambda was deployed will not trigger execution. If multiple blocks were created since the lambda was last triggered, an array of blocks is given to the handler. The range of blocks is always continuous between executions, so no blocks are missed.
engine.onBlocks(handler, { network,// required string - Network ID per supported networks concurrency,// optional string - "single" for single node (default), "multiple" for multiple nodes});
asyncfunctionhandler(args) {args.web3 // initialized web3 object according to the networkargs.fromBlock // number - the first block number in the rangeargs.toBlock // number - the last block number in the rangeargs.guardians /* key-value object of Guardians data: { "NEOPLY": { "weight": 279476867, "nodeAddress": "0xf8cd99a88707c4fc64ac91f237af8570a83cc018", "guardianAddress": "0x9520f53fd81c668e8088ae194c40e3f977b73d28", "ip": "54.95.108.148", "currentNode": true }, "오뽀가디언 - WhaleCoreStake - ORBS KOREA - ": { "weight": 134901962, "nodeAddress": "0x8cd2a24f0c3f50bce2f12c846277491433b47ae0", "guardianAddress": "0xc5e624d6824e626a6f14457810e794e4603cfee2", "ip": "34.227.204.75", "currentNode": false }, }....*/}
Example
// run every time there are new blocks on BNB Chainengine.onBlocks(handler, { network:"bsc" });