deprecated
  • orbs-v3 overview
  • orbs-vm
    • Introduction
    • Get started
    • Dockerfile
      • Working Directory
      • Entry point
      • Health check
    • Status
    • Deployment
  • orbs-lambda
    • Introduction
    • Getting Started
    • Supported Networks
    • Project Structure
    • Lambda Triggers
      • OnSchedule
      • onBlocks
      • onEvent
      • Subscribing To Triggers
    • Writing Your Lambda Function
    • Test And Run Locally
    • Paying For Your Transactions
    • Submit Your Lambda
Powered by GitBook
On this page
  • Web3
  • storage
  • guardians
  • config
  • event
  • fromBlock
  • toBlock
  1. orbs-lambda

Writing Your Lambda Function

PreviousSubscribing To TriggersNextTest And Run Locally

Last updated 2 years ago

Your Lambda should be written as a regular JS function.

Upon runtime, the backend process invokes your task function within a set of parameters according to its trigger type:

// This task is planned to run on a time-based trigger
function myScheduledTask(web3, storage, guardians, config) {
    // do hard work
}

// This task is planned to run as reaction to events being emitted
function myEventsTask(web3, storage, guardians, config, event) {
    // do hard work
}

// This task is planned to run on block ranges
function myBlocksTask(web3, storage, guardians, config, fromBlock, toBlock) {
    // do hard work
}

Web3

Initialized object for interacting with the blockchain. Comes with pre-injected RPC provider, aw well as account credentials for signing transactions.

storage

Storage handler. Supports the following methods:

set(key, value, [options])

Set key to hold the string value. If key already holds a value, it is overwritten. Any previous time to live (ttl) associated with the key is discarded on successful SET operation. Max value size is 1 KB.

options:

  • ttl: Set the specified expire time, in seconds.

get(key)

Get the value of key. If the key does not exist the special value undefined is returned.

remove(key)

Removes the specified keys. A key is ignored if it does not exist.

guardians

Array of guardians (executors) addresses.

config

event

(only relevant for onEvent)

fromBlock

(only relevant for onBlocks)

The first block in the range to be scanned for potential triggers.

toBlock

(only relevant for onBlocks)

The last block in the range to be scanned for potential triggers.

key:value object containing the configuration, which you supply when .

The object which was emitted.

web3.js
defining the trigger
Event