Skip to content

Conversation

@poopoothegorilla
Copy link
Contributor

@poopoothegorilla poopoothegorilla commented Jan 29, 2026

https://smartcontract-it.atlassian.net/browse/DEVSVCS-3734

$ ../cre workflow simulate ./my-workflow 
{"level":"info","chain-id":4801,"time":"2026-01-29T08:51:12-05:00","message":"Added experimental chain"}
{"level":"info","chain-id":480,"time":"2026-01-29T08:51:12-05:00","message":"Added experimental chain"}
Warning: using default private key for chain write simulation. To use your own key, set CRE_ETH_PRIVATE_KEY in your .env file or system environment.
Workflow compiled
2026-01-29T08:51:14Z [SIMULATION] Simulator Initialized

2026-01-29T08:51:14Z [SIMULATION] Running trigger [email protected]
2026-01-29T08:51:14Z [USER LOG] msg="Cron trigger fired" scheduledTime=2026-01-29T13:51:14.709Z
2026-01-29T08:51:14Z [USER LOG] msg="Experimental chains available" worldchain-sepolia=4801 worldchain-mainnet=480

Workflow Simulation Result:
 {
  "Result": "Cron fired at 2026-01-29 13:51:14.709344 +0000 UTC"
}

2026-01-29T08:51:14Z [SIMULATION] Execution finished signal received
2026-01-29T08:51:14Z [SIMULATION] Skipping WorkflowEngineV2
//go:build wasip1

package main

import (
        "fmt"
        "log/slog"

        "github.com/smartcontractkit/cre-sdk-go/capabilities/scheduler/cron"
        "github.com/smartcontractkit/cre-sdk-go/cre"
        "github.com/smartcontractkit/cre-sdk-go/cre/wasm"
)

// Worldchain chain IDs (experimental chains)
// These can be used with evm.Client{ChainSelector: WorldchainSepoliaChainID}
// when the experimental-chains config is set up in project.yaml
const (
        WorldchainSepoliaChainID = 4801 // Worldchain Sepolia testnet
        WorldchainMainnetChainID = 480  // Worldchain Mainnet
)

type ExecutionResult struct {
        Result string
}

// Workflow configuration loaded from the config.json file
type Config struct {
        // Address to check balance for on Worldchain (for future use)
        TargetAddress string `json:"targetAddress"`
}

// Workflow implementation with a list of capability triggers
func InitWorkflow(config *Config, logger *slog.Logger, secretsProvider cre.SecretsProvider) (cre.Workflow[*Config], error) {
        // Create the cron trigger
        cronTrigger := cron.Trigger(&cron.Config{Schedule: "*/30 * * * * *"}) // Fires every 30 seconds

        // Register a handler with the trigger and a callback function
        return cre.Workflow[*Config]{
                cre.Handler(cronTrigger, onCronTrigger),
        }, nil
}

func onCronTrigger(config *Config, runtime cre.Runtime, trigger *cron.Payload) (*ExecutionResult, error) {
        logger := runtime.Logger()
        scheduledTime := trigger.ScheduledExecutionTime.AsTime()
        logger.Info("Cron trigger fired", "scheduledTime", scheduledTime)

        // Log that experimental chains are configured
        // In a real workflow, you would use:
        //   evmClient := &evm.Client{ChainSelector: WorldchainSepoliaChainID}
        // to interact with the experimental chain
        logger.Info("Experimental chains available",
                "worldchain-sepolia", WorldchainSepoliaChainID,
                "worldchain-mainnet", WorldchainMainnetChainID)

        return &ExecutionResult{
                Result: fmt.Sprintf("Cron fired at %s", scheduledTime),
        }, nil
}

func main() {
        wasm.NewRunner(cre.ParseJSON[Config]).Run(InitWorkflow)
}%
staging-settings:
  rpcs:
    - chain-name: ethereum-testnet-sepolia
      url: https://ethereum-sepolia-rpc.publicnode.com
  experimental-chains:
    # Worldchain Sepolia (testnet) - Chain ID 4801
    - chain-id: 4801
      rpc-url: "https://worldchain-sepolia.g.alchemy.com/public"
      forwarder: "0x76c9cf548b4179F8901cda1f8623568b58215E62"
    # Worldchain Mainnet - Chain ID 480
    - chain-id: 480
      rpc-url: "https://worldchain-mainnet.g.alchemy.com/public"
      forwarder: "0x6E9EE680ef59ef64Aa8C7371279c27E496b5eDc1"

@github-actions
Copy link

👋 poopoothegorilla, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!


// Skip if chain ID already exists (supported chain takes precedence)
if _, exists := clients[ec.ChainID]; exists {
h.log.Debug().Uint64("chain-id", ec.ChainID).Msg("Experimental chain ID conflicts with supported chain; skipping")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm unsure if this is the right behaviour. They could have an on-chain contract that expects the old forwarder (in the event that it changed for any reason).

I would check if it's the same, if it is, then emit a debug, if it's not respect their wishes and emit a warning.

@wentzeld what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

went ahead and put this in... we can always change if needed

Copy link
Contributor

@timothyF95 timothyF95 left a comment

Choose a reason for hiding this comment

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

lgtm

@poopoothegorilla poopoothegorilla added this pull request to the merge queue Jan 29, 2026
Merged via the queue into main with commit d5728f0 Jan 29, 2026
21 checks passed
@poopoothegorilla poopoothegorilla deleted the jtw/experimental-chains-simulator branch January 29, 2026 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants