Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions building-blocks/indexer-block-trigger/README.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this README.md can be copied into workflow/README.md both for GO and TS versions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the workflow/README.md both for GO and TS versions respectively with their respective READMEs. I still left this README in place for a general reference and I added some alchemy helpers as well.

Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# CRE Indexer Block Trigger Workflows

Workflows for processing new blocks and transactions using block-triggered webhooks (from Alchemy Notify) and matching
against watched addresses. These workflows demonstrate the **block trigger pattern** where the workflow reacts to
incoming block data and extracts relevant transactions.

## Directory Structure

```
building-blocks/indexer-block-trigger/
├── block-trigger-go/ (Go-based workflow)
│ └── workflow/
│ ├── main.go
│ ├── config.staging.json
│ ├── config.production.json
│ ├── workflow.yaml
│ └── README.md
├── block-trigger-ts/ (TypeScript-based workflow)
└── workflow/
├── main.ts
├── package.json
├── config.staging.json (optional)
├── workflow.yaml
└── README.md

```

## Overview

These workflows demonstrate how to:
- React to block events via HTTP webhook triggers
(We use Alchemy Notify for this workflow)
- Match transactions to a list of watched addresses
- Process and return JSON-formatted block and transaction data
- Implement the same logic in both Go and TypeScript

Both workflows process incoming block data and extract:
- Block number, hash, timestamp
- All transactions in the block
- Transactions where the `to` address matches a watched address

## Workflows

### 1. block-trigger-go (Go Implementation)

**Language:** Go

**Features:**
- Uses `http.Trigger` from CRE Go SDK
- Matches transactions to watched addresses from config
- Returns formatted JSON summary of block and matched transactions

**Running the workflow:**
```bash
cd building-blocks/indexer-block-trigger/block-trigger-go
cre workflow simulate workflow --non-interactive --trigger-index 0 --http-payload test-block.json --target staging-settings
```

### 2. block-trigger-ts (TypeScript Implementation)

**Language:** TypeScript

**Features:**
- Uses HTTP trigger from CRE TypeScript SDK
- Matches transactions to watched addresses from config
- Returns formatted JSON summary of block and matched transactions

**Running the workflow:**
```bash
cd building-blocks/indexer-block-trigger/block-trigger-ts/workflow
bun install
cre workflow simulate workflow --non-interactive --trigger-index 0 --http-payload test-block.json --target staging-settings
```

## Setup and Testing

### Prerequisites

**For Go workflow:**
1. Install CRE CLI
2. Login: `cre login`
3. Install Go

**For TypeScript workflow:**
1. Install CRE CLI
2. Login: `cre login`
3. Install Bun (or Node.js)
4. Run `bun install` in the workflow directory

### Running the Workflows

**Go Workflow:**
```bash
cd building-blocks/indexer-block-trigger/block-trigger-go
cre workflow simulate workflow --non-interactive --trigger-index 0 --http-payload test-block.json --target staging-settings
```

**TypeScript Workflow:**
```bash
cd building-blocks/indexer-block-trigger/block-trigger-ts
cre workflow simulate workflow --non-interactive --trigger-index 0 --http-payload test-block.json --target staging-settings
```

### Example Output

Both workflows return JSON output like:

```json
{
"blockNumber": 12345678,
"blockHash": "0xabc...",
"timestamp": 1700000000,
"totalLogs": 42,
"uniqueTransactions": 10,
"matchedTransactions": 2,
"transactions": [
{
"hash": "0xdef...",
"from": "0x...",
"to": "0x73b668d8374ddb42c9e2f46fd5b754ac215495bc",
"value": "1000000000000000000",
...
}
]
}
```

## Example Use Cases

### 1. Monitoring High-Value Addresses
Track transactions to specific addresses in real time:
```json
{
"watchedAddresses": ["0x...", "0x..."]
}
```

### 2. Contract Interaction Tracking
Detect when contracts of interest receive transactions:
```json
{
"watchedAddresses": ["0xContract1", "0xContract2"]
}
```

### 3. Block-Level Analytics
Summarize block activity and matched transactions for analytics dashboards.

## Reference Documentation

- [CRE Documentation](https://docs.chain.link/cre)
- [Alchemy Webhooks](https://www.alchemy.com/docs/reference/custom-webhook)

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.env
19 changes: 19 additions & 0 deletions building-blocks/indexer-block-trigger/block-trigger-go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module block-trigger-go

go 1.25.3

require (
github.com/smartcontractkit/cre-sdk-go v1.0.0
github.com/smartcontractkit/cre-sdk-go/capabilities/networking/http v0.10.0
)

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20250918131840-564fe2776a35 // indirect
github.com/stretchr/testify v1.11.1 // indirect
google.golang.org/protobuf v1.36.7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
24 changes: 24 additions & 0 deletions building-blocks/indexer-block-trigger/block-trigger-go/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20250918131840-564fe2776a35 h1:hhKdzgNZT+TnohlmJODtaxlSk+jyEO79YNe8zLFtp78=
github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20250918131840-564fe2776a35/go.mod h1:jUC52kZzEnWF9tddHh85zolKybmLpbQ1oNA4FjOHt1Q=
github.com/smartcontractkit/cre-sdk-go v1.0.0 h1:O52/QDmw/W8SJ7HQ9ASlVx7alSMGsewjL0Y8WZmgf5w=
github.com/smartcontractkit/cre-sdk-go v1.0.0/go.mod h1:CQY8hCISjctPmt8ViDVgFm4vMGLs5fYI198QhkBS++Y=
github.com/smartcontractkit/cre-sdk-go/capabilities/networking/http v0.10.0 h1:nP6PVWrrTIICvjwQuFitsQecQWbqpPaYzaTEjx92eTQ=
github.com/smartcontractkit/cre-sdk-go/capabilities/networking/http v0.10.0/go.mod h1:M83m3FsM1uqVu06OO58mKUSZJjjH8OGJsmvFpFlRDxI=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
google.golang.org/protobuf v1.36.7 h1:IgrO7UwFQGJdRNXH/sQux4R1Dj1WAKcLElzeeRaXV2A=
google.golang.org/protobuf v1.36.7/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# ==========================================================================
# CRE PROJECT SETTINGS FILE
# ==========================================================================
# Project-specific settings for CRE CLI targets.
# Each target defines cre-cli, account, and rpcs groups.
#
# Example custom target:
# my-target:
# account:
# workflow-owner-address: "0x123..." # Optional: Owner wallet/MSIG address (used for --unsigned transactions)
# rpcs:
# - chain-name: ethereum-mainnet # Required: Chain RPC endpoints
# url: "https://mainnet.infura.io/v3/KEY"

# ==========================================================================
staging-settings:
rpcs:
- chain-name: ethereum-testnet-sepolia
url: https://ethereum-sepolia-rpc.publicnode.com

# ==========================================================================
production-settings:
rpcs:
- chain-name: ethereum-testnet-sepolia
url: https://ethereum-sepolia-rpc.publicnode.com
- chain-name: ethereum-mainnet
url: https://mainnet.infura.io/v3/<YOUR-PROJECT-ID>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
secretsNames:
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Blank Workflow Example

This template provides a blank workflow example. It aims to give a starting point for writing a workflow from scratch and to get started with local simulation.

Steps to run the example

## 1. Update .env file

You need to add a private key to env file. This is specifically required if you want to simulate chain writes. For that to work the key should be valid and funded.
If your workflow does not do any chain write then you can just put any dummy key as a private key. e.g.
```
CRE_ETH_PRIVATE_KEY=0000000000000000000000000000000000000000000000000000000000000001
```

## 2. Simulate the workflow
Run the command from <b>project root directory</b>

```bash
cre workflow simulate <path-to-workflow> --target=staging-settings
```

It is recommended to look into other existing examples to see how to write a workflow. You can generate then by running the `cre init` command.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"watchedAddresses": [
"0x73b668d8374ddb42c9e2f46fd5b754ac215495bc",
"0x6edce65403992e310a62460808c4b910d972f10f"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"watchedAddresses": [
"0x73b668d8374ddb42c9e2f46fd5b754ac215495bc",
"0x6edce65403992e310a62460808c4b910d972f10f"
]
}
Loading
Loading