Functions Overview
SendBlocks Functions are designed to enable you to execute your code in response to any on-chain event and instantly stream the results to your backend
🧑💻 You
- Choose a blockchain Trigger (specific address transcation, contract event and etc...)
- Write a Function that executes once that trigger occurs
- Deploy a Webhook that will receive the function result
🎣 Sendblocks
- Catches the block with the relevant trigger, executes your function and delivers the result to your webhook address in Real Time
High-Level Workflow
- You imagine something occurring on the blockchain that you want to know about and respond to.
- You write a function that acts upon the occurrence you imagined and deploy it to the SendBlocks platform.
- We scan the blockchain for occurrences that match your trigger and call your function when we find a match.
- You receive the output of your function directly into your backend using a webhook.
In More Detail
Our engine constantly runs in the background, scanning the blockchain for occurrences of interest. These occurrences can be as simple as an address showing up in the "to" field of a transaction, or as complex as an internal transaction affecting a mapping with a specific key. These occurrences are stored so they can be queried later, and are used to trigger user functions.
When deploying a SendBlocks function, you need to specify:
- Triggers: One or more conditions that must be met before your function will be called. Trigger types are discussed in the following page.
- A Webhook ID: The ID that is returned from the webhook creation endpoint, which determines where to send the output of your function.
- Function Code: The code that will be executed when your function is triggered. We currently support Javascript and Typescript. See the Writing Functions section for more details.
Once your function is deployed, our engine will call it when an occurrence that matches its triggers is identified.
Functions are called with an object that contains information about the occurrence that triggered its invocation. This can be a transaction, an emitted event, or even an entire block, depending on the trigger.
Functions run inside a secure sandbox environment which is disconnected from the internet but has access to blockchain nodes. Don't worry, though, as we've brought all the libraries you know and love with us! (You can read more about that under Importing Libraries).
Function Output
Once your function has completed, we will evaluate its return value, stdout
and stderr
streams and forward the resulting composite JSON object to the URL of your function's webhook.
See Function Output for more on sending a function invocation's results to your webhooks.
Updated 29 days ago