A framework for building custom Code Nodes in Herd Trails. This package provides the tools and utilities needed to create Deno scripts that can transform data, make web requests, and perform custom logic within your Trail workflow.
// Use directly in your Herd Deno scriptimport{initializeHerdCodeServer,EVMAddress,Bytes}from"npm:@herd-labs/trails-code-framework";Below is an example Deno script that makes use of the Trails Code Framework:
import{initializeHerdCodeServer}from"npm:@herd-labs/trails-code-framework";import{z}from"npm:zod";// Define your input and output schemas using Zod. These can be named anything, we currently do not support arrays or nested objects (tuples).constinputSchema=z.object({a: z.number(),b: z.number(),});constoutputSchema=z.object({sum: z.number(),});// Create your main function (can be named anything, use z.infer to type your inputs/outputs)asyncfunctionhandler(input: z.infer<typeofinputSchema>): Promise<z.infer<typeofoutputSchema>>{return{sum: input.a+input.b,};}// This default export initializes the Trails Code Framework on DenoexportdefaultinitializeHerdCodeServer(inputSchema,outputSchema,handler);Creates a validated HTTP endpoint with automatic request/response validation.
Parameters:
inputSchema: Zod schema for input validationoutputSchema: Zod schema for output validationhandler: Function that processes the validated input and returns the output
Returns: Herd-compliant code ready for use in a Trail!
TBD