SDK Reference

This section provides a detailed technical reference for the public interfaces of the CRE TypeScript SDK. Use this reference for quick lookups of specific functions, types, and method signatures.

How to read this section

The SDK Reference is broken down into several pages, each corresponding to a core part of the SDK's functionality:

  • Core SDK: Covers the fundamental building blocks of any workflow, including cre.handler, Runtime, and the .result() pattern for promise resolution.
  • Triggers: Details the configuration and payload structures for all available trigger types (Cron, HTTP, EVM Log).
  • EVM Client: Provides a reference for the cre.capabilities.EVMClient, the primary tool for all EVM interactions, including reads and writes.
  • HTTP Client: Provides a reference for the cre.capabilities.HTTPClient, used for making offchain API requests from individual nodes.
  • Consensus & Aggregation: Describes how to use aggregators like consensusMedianAggregation and ConsensusAggregationByFields with runtime.runInNodeMode() to process and consolidate data from multiple nodes.

Package Structure

The TypeScript SDK is distributed as a single npm package @chainlink/cre-sdk that exports all necessary functionality:

import {
  cre, // Main SDK namespace with capabilities
  Runner, // Workflow runner
  type Runtime, // Runtime interface
  type NodeRuntime, // Node-level runtime interface
  consensusMedianAggregation, // Consensus aggregators
  getNetwork, // Chain selector utilities
  bytesToHex, // Data conversion utilities
  hexToBase64,
  // ... and more
} from "@chainlink/cre-sdk"

Understanding TypeScript Types

The TypeScript SDK uses Protocol Buffers for type definitions, which generates two type representations for each message:

  • Type (e.g., CallMsg): Runtime types using Uint8Array, protobuf BigInt, and protobuf Message objects. These are efficient for in-memory processing.
  • TypeJson (e.g., CallMsgJson): JSON-serializable types using string, number, and plain objects. These are used for serialization and I/O operations.

As a developer, you always use JSON types. The SDK automatically converts between representations when crossing WASM boundaries.

// You write (JSON types - convenient):
evmClient.callContract(runtime, {
  call: {
    from: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb", // string (hex)
    to: "0x123...",
    data: "0xabc...",
  },
  blockNumber: "12345", // string representation
})

// SDK handles internally (native types - efficient):
// - Converts strings to Uint8Array
// - Processes with protobuf types
// - Converts results back to JSON types for your callback

In this reference documentation, type tables show JSON types only, as these are what you'll use when writing workflows.

Working with Contract ABIs

The TypeScript SDK integrates with viem for type-safe contract interactions. You define ABIs directly in TypeScript files and use viem's functions for encoding and decoding. For detailed examples and best practices, see the Onchain Read guide.

Runtime Environment

TypeScript workflows are compiled to WebAssembly (WASM) using Javy and QuickJS. This compilation process has implications for library compatibility and available Node.js APIs. See TypeScript Runtime Environment for details on the compilation pipeline, QuickJS compatibility, and how to verify library compatibility.

Runtime Requirements

  • Bun: >= 1.2.21
  • TypeScript: >= 5.9
  • Dependencies: viem (^2.34.0), zod (^3.25.76)

Get the latest Chainlink content straight to your inbox.