Project overview and root directory file structure
When you run thetenderly actions init command, the Tenderly CLI will create an actions root directory along with the necessary files. By default, the actions root directory is named actions.
However, you’re able to specify another name during the initialization process. Once initialized, the name of the root directory can still be adjusted by changing the folder name and the sources field inside the tenderly.yaml file.
An example of a TypeScript-based Web3 Actions project structure:
example
actions/example.ts: By default, this file contains all Web3 Actions.tenderly.yaml: This is a configuration file that specifies settings for all Web3 Actions in a projecttenderly-schema.json: Auto-generated JSON Schema that enables IDE validation and autocomplete fortenderly.yaml, do not edittenderly-schema.jsonby hand
The tenderly.yaml file structure
Thetenderly.yaml file contains configurations and settings for a Tenderly project and all Web3 Actions.
For the purpose of this guide, the completed example tenderly.yaml file will look like this:
example.yaml
The
$schema field is automatically added by tenderly actions init and points to the generated
tenderly-schema.json file. IDEs that support JSON Schema (VS Code, JetBrains) use this to provide
autocompletion and inline validation while you edit tenderly.yaml. The schema file is also
regenerated any time you run tenderly actions init. Add tenderly-schema.json to your
.gitignore if you prefer not to commit it.tenderly.yaml as containing two primary sections:
- General configuration: A section containing the name of the account and project the Web3 Action is associated with.
- Web3 Actions configuration: A section containing configurations for the Web3 Action itself, essentially informing Tenderly when it should be run.
General configuration
The general configuration section includes the following key-value pairs:example.yaml
account_id: Your usernameproject_slug: Slug of the project associated with the Web3 Action (optional, can be left empty)
Web3 Actions configuration
Theactions object is where you start defining your Web3 Actions, including the project settings, such as runtime, sources location, and the actual Web3 Action declaration.
example.yaml
Specifying the project
Start by specifying the composite key that uniquely identifies the project within Tenderly.username/project-slug: Username and project slug for projects belonging to individual developersorg-name/project-slug: Organization name and project slug if your project belongs to an organization
It’s possible to use the same Web3 Actions project for multiple projects you have access to in the
Tenderly Dashboard.
Configuring the runtime
Next, you need to specify the runtime version and the directory that contains your Web3 Action code. This data is used by the Tenderly CLI to bundle and deploy your code to the Web3 Actions runtime on Tenderly’s infrastructure. The following settings are mandatory:runtime: The runtime version. Currently, we support v2, which corresponds to Node 20.sources: The location of Web3 Action source files. The value must be a path pointing to the actions root directory, relative to the folder containing thetenderly.yamlfile. It should match the path you specified when running the init command.
web3-actions.
example
If you change the
sources value, a directory must exist at the specified path, relative to the
actions root, and it must contain your source files with Web3 Action functions.Defining Web3 Actions settings
Individual Web3 Actions are declared under thespecs object. You can declare multiple Web3 Actions in a single tenderly.yaml file.
Each Web3 Action must start with a key that represents the action name (bestActionEver). The action name must be unique at the project level and must begin with a letter followed by letters, digits, hyphens, or underscores (pattern: ^[a-zA-Z][a-zA-Z0-9_-]*$). This key denotes how the deployed Web3 Action is named and represented in the Tenderly Dashboard.
The description key must also be included. The description is generally a sentence or two that describes what a Web3 Action does.
example.yaml
function key to link to the action function you want to run. Source code for Web3 Actions can be split among multiple files or nested in a custom directory structure. The tenderly.yaml file allows for seamless referencing.
For example, a function bestActionEver located in actions/very/organized/file.ts would be referenced in the yaml like so:
example.yaml
bestActionEver Web3 Action will run once every 10 blocks get mined on Rinkeby.
example.yaml