Nodes

Documentation for Nodes in the EigenLayer-AVS system.

Purpose#

This document provides a comprehensive overview of Nodes in the AVA SDK JS. Nodes are the fundamental building blocks of workflows, representing individual tasks or actions that can be performed as part of an automated process. This page details the various types of nodes available, their configuration options, and how to use them effectively in your workflows.

For information about how nodes fit into the larger workflow system, see Workflow System. For details on how workflows are triggered, see Triggers. For information about workflow execution, see Executions.

Overview#

Nodes are modular components that perform specific operations within a workflow. Each node represents a discrete task, such as transferring ETH, interacting with a smart contract, making API calls, or controlling the flow of execution. Nodes are connected by edges to form a directed graph, which defines the execution flow of a workflow.

Sources:

Node Architecture#

In the AVA SDK, nodes are created using the NodeFactory, which provides a consistent interface for creating nodes of different types. Each node has a unique identifier, a name, a type, and type-specific configuration data.

Sources:

Node Types#

The AVA SDK supports a variety of node types, each designed for specific operations. These can be categorized into three main groups:

  1. Blockchain Interaction Nodes: Interact with blockchain networks
  2. External API Nodes: Communicate with external services
  3. Flow Control Nodes: Control the execution flow of the workflow

The following table summarizes the available node types:

CategoryNode TypeDescription
Blockchain InteractionETHTransferTransfers ETH to a specified address
Blockchain InteractionContractWriteExecutes write operations on smart contracts
Blockchain InteractionContractReadReads data from smart contracts
External APIRestAPIMakes HTTP requests to REST APIs
External APIGraphQLQueryExecutes GraphQL queries
Flow ControlBranchImplements conditional logic
Flow ControlFilterFilters data based on conditions
Flow ControlLoopIterates over collections
UtilityCustomCodeExecutes user-defined code

Sources:

Node Type Hierarchy#

Sources:

Blockchain Interaction Nodes#

These nodes interact with blockchain networks to perform operations such as transferring ETH or interacting with smart contracts.

ETHTransferNode#

The ETHTransferNode is used to transfer ETH from the workflow's smart wallet to a specified destination address.

Configuration properties:

  • destination: The recipient's Ethereum address
  • amount: The amount of ETH to transfer (in wei)

Example:

Sources:

ContractWriteNode#

The ContractWriteNode is used to execute state-changing operations on smart contracts, such as transferring tokens or updating contract state.

Configuration properties:

  • contractAddress: The address of the smart contract
  • callData: The encoded function call data
  • contractAbi: The ABI of the smart contract

Example:

Sources:

ContractReadNode#

The ContractReadNode is used to read data from smart contracts without changing state.

Configuration properties:

  • contractAddress: The address of the smart contract
  • callData: The encoded function call data
  • contractAbi: The ABI of the smart contract

Example:

Sources:

External API Nodes#

These nodes interact with external APIs to fetch or send data.

RestAPINode#

The RestAPINode is used to make HTTP requests to REST APIs.

Configuration properties:

  • url: The URL of the API endpoint
  • method: The HTTP method (GET, POST, PUT, DELETE, etc.)
  • body: The request body (for POST, PUT requests)
  • headersMap: Headers to include in the request

Example:

Sources:

GraphQLQueryNode#

The GraphQLQueryNode is used to execute GraphQL queries.

Configuration properties:

  • url: The URL of the GraphQL endpoint
  • query: The GraphQL query string
  • variablesMap: Variables to include in the query

Example:

Sources:

Flow Control Nodes#

These nodes control the execution flow of the workflow based on conditions or collections.

BranchNode#

The BranchNode implements conditional logic by evaluating expressions and determining which branch of the workflow to execute.

Configuration properties:

  • conditionsList: A list of conditions to evaluate

Example:

Sources:

FilterNode#

The FilterNode filters data based on a specified expression.

Configuration properties:

  • expression: The filtering expression
  • input: The input data to filter

Example:

Sources:

LoopNode#

The LoopNode iterates over a collection and executes a specified node for each item.

Configuration properties:

  • input: The collection to iterate over
  • iterVal: The variable name for the current item
  • iterKey: The variable name for the current index
  • One of the node types to execute for each iteration

Example:

Sources:

Utility Nodes#

CustomCodeNode#

The CustomCodeNode executes user-defined code.

Configuration properties:

  • lang: The language of the code (currently only JavaScript is supported)
  • source: The source code to execute

Example:

Sources:

Creating Nodes with NodeFactory#

The NodeFactory provides a convenient way to create nodes. It offers two methods:

  • createNodes(nodeConfigs: NodeConfig[]): Creates multiple nodes from an array of configurations
  • create(nodeConfig: NodeConfig): Creates a single node from a configuration

Example usage:

Sources:

Node Data Templates and Dynamic Values#

Node data properties can include template expressions that are evaluated at runtime. Templates use the {{ expression }} syntax and can reference outputs from previous nodes, trigger data, and context variables.

Example:

In this example:

  • {{apContext.configVars.bot_token}} references a configuration variable
  • {{ chatId }} references a variable in the context
  • {{ checkPrice.data.toString() }} references the output of a previous node named "checkPrice"

Sources:

Node Execution and Outputs#

When a workflow is executed, each node is processed in the order defined by the workflow's edges. Each node type produces a specific output structure that can be referenced by subsequent nodes.

Each node type produces different output structures:

Node TypeOutput StructureDescription
ETHTransferNode{ transactionHash: string }Hash of the transaction
ContractWriteNode{ userOp: UserOp, txReceipt: TransactionReceipt }User operation and transaction receipt
ContractReadNode{ dataList: Value[] }Array of return values
RestAPINode{ data: any }Response data
GraphQLQueryNode{ data: any }Query result data
BranchNode{ conditionId: string }ID of the matched condition
FilterNode{ data: any }Filtered data
LoopNode{ data: string }Aggregated results
CustomCodeNode{ data: any }Returned data from the code

Sources:

Error Handling#

If a node execution fails, the error is captured in the execution record, and the workflow may continue or stop depending on the workflow configuration. Error information includes:

  • Error message
  • Node ID that failed
  • Execution start and end timestamps

Sources:

Practical Examples#

Example 1: Price Oracle Workflow#

The following example creates a workflow that:

  1. Reads price data from a Chainlink price oracle smart contract
  2. Sends the price data to a Telegram chat

Sources:

Example 2: Token Transfer Monitoring Workflow#

This example creates a workflow that monitors for ERC-20 token transfers to a specific address and sends a notification when a transfer over a certain amount occurs:

Sources:

Conclusion#

Nodes are the fundamental building blocks of workflows in the AVA SDK. They enable a wide range of operations, from blockchain interactions to external API calls and flow control. By combining different node types and connecting them with edges, you can create complex automation workflows that respond to various triggers and perform actions based on conditions and data.

By understanding the different node types and their configuration options, you can leverage the full power of the AVA SDK to create sophisticated automation solutions for your blockchain applications.