Prerequisites
You need to have npm and the Tenderly CLI installed and properly configured on your local machine. Check out the Web3 Actions CLI Cheatsheet for installation instructions.Initializing a Web3 Actions Project
Navigate to the folder on your system where you want to place your Web3 Action code and the following command to initialize a new Web3 Actions project:example
example
.png?fit=max&auto=format&n=XsEZlaGXYskrtN68&q=85&s=5191970c6b2a63a0ee869429dbeaf725)

example
Building and deploying the Web3 Action
These are the steps we need to take to build and deploy a Web3 Action:- Create the action function
- Configure the block trigger to run the function
- Deploy the code to Tenderly using the CLI
Creating an action function
Copy the following code into the example.ts file:example.tsx
Context object and an Event object.
Contextobject enables access to Storage and Secrets. You can read more about it here.- The and the
eventargument is an object containing information about the external (on-chain) event that triggered the action. Because we want to run this action on a block-related event, theeventargument will be of typeBlockEvent. TheBlockEventobject contains information about the block that was mined, such as the block number, the block hash, and the block timestamp.
Configuring the trigger in tenderly.yaml for a new action
Step 1: Replace the content of thetenderly.yaml file with the following:
example.yaml
username and project-slug with your username and the slug of your project.
Check out this guide to learn how to find the organization name, username, and project slug.
Notes:
The tenderly.yaml file contains specifications of triggers for each action in the project and links the trigger to an action function. Here, we’re creating an action called block-number-printer.
- The
functionproperty is referencing theblockHelloWorldFnfunction from the example.ts file. - This action will be triggered on each 10th block mined on network 1, as per the
triggerproperty.
Building and deploying actions
Go back to terminal and run the following command to deploy all Web3 Actions you defined. After successful deployment, you will be able to see the actions in the Tenderly UI.example
Zero downtime upgrade of Web3 Actions\ To upgrade a Web3 Action, just edit the source code
and/or tenderly.yaml and run
tenderly actions deploy.Before you go
Keep in mind:- You must run the
deploycommand from the folder containing tenderly.yaml file. - If you initialize actions for multiple Tenderly projects in the same directory, upon running
deployyou will be asked to select a project. Only actions belonging to the selected project will be deployed. - All actions belonging to one project are deployed simultaneously.
- Any file referenced from the JavaScript/TypeScript must be in the actions root. Do not reference files outside of this folder.
Resources
- Learn more about Web3 Actions Functions, Events, and Triggers.
- Learn more about Context, Storage, and Secrets.
- Learn more about Project Structure and tenderly.yaml configuration.