Skip to content

Commit ca264c1

Browse files
authored
various updates to SDK reference and examples (#3307)
1 parent efbd914 commit ca264c1

File tree

7 files changed

+184
-24
lines changed

7 files changed

+184
-24
lines changed

src/content/cre/guides/workflow/using-triggers/http-trigger/configuration-go.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func onHttpTrigger(config *Config, runtime cre.Runtime, payload *http.Payload) (
4444
logger := runtime.Logger()
4545

4646
// Unmarshal the JSON input from bytes
47-
var requestData map[string]interface{}
47+
var requestData map[string]any
4848
if err := json.Unmarshal(payload.Input, &requestData); err != nil {
4949
return nil, fmt.Errorf("failed to unmarshal input: %w", err)
5050
}
@@ -92,7 +92,7 @@ func onHttpTrigger(config *Config, runtime cre.Runtime, payload *http.Payload) (
9292

9393
// The payload.Input is []byte containing JSON data.
9494
// Unmarshal it into a map or a custom struct.
95-
var requestData map[string]interface{}
95+
var requestData map[string]any
9696
if err := json.Unmarshal(payload.Input, &requestData); err != nil {
9797
return nil, fmt.Errorf("failed to unmarshal input: %w", err)
9898
}

src/content/cre/llms-full-go.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4174,7 +4174,7 @@ By default, `cre workflow simulate` performs a dry run without broadcasting tran
41744174
cre workflow simulate my-workflow --broadcast --target staging-settings
41754175
```
41764176

4177-
See the [CLI Reference](/cre/reference/cli#cre-workflow-simulate) for more details.
4177+
See the [CLI Reference](/cre/reference/cli/workflow#cre-workflow-simulate) for more details.
41784178

41794179
## Troubleshooting
41804180

@@ -9758,7 +9758,7 @@ go mod tidy
97589758
<Aside type="note" title="Funding Your Account">
97599759
This step submits an onchain transaction, which requires gas. Before running the simulation, verify that the account
97609760
associated with the private key from [Part
9761-
1](/cre/getting-started/part-1-project-setup#step-3-configure-the-environment) is funded with sufficient Sepolia ETH.
9761+
1](/cre/getting-started/part-1-project-setup-go#set-up-your-private-key) is funded with sufficient Sepolia ETH.
97629762
An unfunded account will cause the transaction to fail, often with an error message like `gas required exceeds
97639763
allowance`.
97649764

@@ -10758,7 +10758,7 @@ The `http.Client` is the SDK's interface for the underlying [HTTP Capability](/c
1075810758
All HTTP requests are wrapped in a consensus mechanism to provide a single, reliable result. The SDK provides two ways to do this:
1075910759

1076010760
- **[`http.SendRequest`](#1-the-httpsendrequest-pattern-recommended):** (Recommended) A high-level helper function that simplifies making requests.
10761-
- **[`cre.RunInNodeMode`](#2-the-cre-runinnodemode-pattern-low-level):** The lower-level pattern for more complex scenarios.
10761+
- **[`cre.RunInNodeMode`](#2-the-creruninnodemode-pattern-low-level):** The lower-level pattern for more complex scenarios.
1076210762

1076310763
## Prerequisites
1076410764

@@ -11640,7 +11640,7 @@ Here are common patterns for formatting reports. Choose the one that matches you
1164011640
| Pattern | When to use |
1164111641
| ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- |
1164211642
| [**Pattern 1: Report in body**](#pattern-1-report-in-body-simplest) | Your API accepts raw binary data and handles decoding |
11643-
| [**Pattern 2: Report + signatures in body**](#pattern-2-report-signatures-in-body) | Your API needs everything concatenated in one binary blob |
11643+
| [**Pattern 2: Report + signatures in body**](#pattern-2-report--signatures-in-body) | Your API needs everything concatenated in one binary blob |
1164411644
| [**Pattern 3: Report in body, signatures in headers**](#pattern-3-report-in-body-signatures-in-headers) | Your API needs signatures separated for easier parsing |
1164511645
| [**Pattern 4: JSON-formatted report**](#pattern-4-json-formatted-report) | Your API only accepts JSON payloads |
1164611646

@@ -12663,7 +12663,7 @@ func onHttpTrigger(config *Config, runtime cre.Runtime, payload *http.Payload) (
1266312663
logger := runtime.Logger()
1266412664

1266512665
// Unmarshal the JSON input from bytes
12666-
var requestData map[string]interface{}
12666+
var requestData map[string]any
1266712667
if err := json.Unmarshal(payload.Input, &requestData); err != nil {
1266812668
return nil, fmt.Errorf("failed to unmarshal input: %w", err)
1266912669
}
@@ -12711,7 +12711,7 @@ func onHttpTrigger(config *Config, runtime cre.Runtime, payload *http.Payload) (
1271112711

1271212712
// The payload.Input is []byte containing JSON data.
1271312713
// Unmarshal it into a map or a custom struct.
12714-
var requestData map[string]interface{}
12714+
var requestData map[string]any
1271512715
if err := json.Unmarshal(payload.Input, &requestData); err != nil {
1271612716
return nil, fmt.Errorf("failed to unmarshal input: %w", err)
1271712717
}
@@ -13211,8 +13211,8 @@ This is a generic interface passed as the final argument to `cre.RunInNodeMode`.
1321113211

1321213212
There are two primary ways to specify an aggregation method:
1321313213

13214-
1. [**Using Built-in Functions**](/cre/reference/sdk/consensus-go/#1-built-in-aggregation-functions): For simple types, you can use functions like [`ConsensusMedianAggregation`](/cre/reference/sdk/consensus/#consensusmedianaggregationt).
13215-
2. [**Using Struct Tags**](/cre/reference/sdk/consensus-go/#2-aggregation-via-struct-tags): For complex types (structs), you can use [`ConsensusAggregationFromTags`](/cre/reference/sdk/consensus/#aggregation-via-struct-tags).
13214+
1. [**Using Built-in Functions**](/cre/reference/sdk/consensus-go/#1-built-in-aggregation-functions): For simple types, you can use functions like [`ConsensusMedianAggregation`](/cre/reference/sdk/consensus-go#consensusmedianaggregationt).
13215+
2. [**Using Struct Tags**](/cre/reference/sdk/consensus-go/#2-aggregation-via-struct-tags): For complex types (structs), you can use [`ConsensusAggregationFromTags`](/cre/reference/sdk/consensus-go#2-aggregation-via-struct-tags).
1321613216

1321713217
## 1. Built-in aggregation functions
1321813218

@@ -13368,7 +13368,7 @@ These interfaces provide access to capabilities and manage the execution context
1336813368

1336913369
- **`cre.Runtime` ("Easy Mode")**: Passed to your main trigger callback, this represents the **DON's (Decentralized Oracle Network) execution context**. It is used for operations that are already guaranteed to be Byzantine Fault Tolerant (BFT). When you use the `Runtime`, you ask the network to execute something, and CRE handles the underlying complexity to ensure you get back one final, secure, and trustworthy result. A common use case is writing a transaction to a blockchain with the EVM client.
1337013370

13371-
- **`cre.NodeRuntime` ("Manual Mode")**: Represents an **individual node's execution context**. This is used when a BFT guarantee cannot be provided automatically (e.g., calling a third-party API). You tell each node to perform a task on its own, and each node returns its own individual answer. You are then responsible for telling the SDK how to combine them into a single, trusted result by providing a consensus and aggregation algorithm. It is used exclusively inside a [`RunInNodeMode`](#sdkruninnodemode) block and is provided by that function—you do not get this type directly in your handler's callback.
13371+
- **`cre.NodeRuntime` ("Manual Mode")**: Represents an **individual node's execution context**. This is used when a BFT guarantee cannot be provided automatically (e.g., calling a third-party API). You tell each node to perform a task on its own, and each node returns its own individual answer. You are then responsible for telling the SDK how to combine them into a single, trusted result by providing a consensus and aggregation algorithm. It is used exclusively inside a [`RunInNodeMode`](#creruninnodemode) block and is provided by that function—you do not get this type directly in your handler's callback.
1337213372

1337313373
To learn more about how to aggregate results from `NodeRuntime`, see the [Consensus & Aggregation](/cre/reference/sdk/consensus) reference.
1337413374

@@ -14638,7 +14638,7 @@ Now you are ready to compile and run the workflow. The workflow code (`workflow.
1463814638
<Aside type="note" title="Onchain Writes are Dry Runs by Default">
1463914639
The `--broadcast` flag is included here because this workflow performs an onchain write. By default, the `simulate`
1464014640
command performs a dry run and will not broadcast the transaction without this flag. For more details, see the `cre
14641-
workflow simulate` [reference](/cre/reference/cli#cre-workflow-simulate).
14641+
workflow simulate` [reference](/cre/reference/cli/workflow#cre-workflow-simulate).
1464214642
</Aside>
1464314643

1464414644
You will first see a `Workflow compiled` message, followed by the trigger selection menu.

src/content/cre/llms-full-ts.txt

Lines changed: 86 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8550,7 +8550,7 @@ main()
85508550
<Aside type="note" title="Funding Your Account">
85518551
This step submits an onchain transaction, which requires gas. Before running the simulation, verify that the account
85528552
associated with the private key from [Part
8553-
1](/cre/getting-started/part-1-project-setup#step-3-configure-your-workflow) is funded with sufficient Sepolia ETH.
8553+
1](/cre/getting-started/part-1-project-setup-ts#set-up-your-private-key) is funded with sufficient Sepolia ETH.
85548554
An unfunded account will cause the transaction to fail, often with an error message like `gas required exceeds
85558555
allowance`.
85568556

@@ -10444,7 +10444,7 @@ Here are common patterns for formatting reports. Choose the one that matches you
1044410444
| Pattern | When to use |
1044510445
| ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- |
1044610446
| [**Pattern 1: Report in body**](#pattern-1-report-in-body-simplest) | Your API accepts raw binary data and handles decoding |
10447-
| [**Pattern 2: Report + signatures in body**](#pattern-2-report-signatures-in-body) | Your API needs everything concatenated in one binary blob |
10447+
| [**Pattern 2: Report + signatures in body**](#pattern-2-report--signatures-in-body) | Your API needs everything concatenated in one binary blob |
1044810448
| [**Pattern 3: Report in body, signatures in headers**](#pattern-3-report-in-body-signatures-in-headers) | Your API needs signatures separated for easier parsing |
1044910449
| [**Pattern 4: JSON-formatted report**](#pattern-4-json-formatted-report) | Your API only accepts JSON payloads |
1045010450

@@ -12077,7 +12077,7 @@ This is a generic type passed as the second argument to `runtime.runInNodeMode()
1207712077
There are two primary ways to specify an aggregation method:
1207812078

1207912079
1. [**Using built-in functions**](/cre/reference/sdk/consensus-ts#1-built-in-aggregation-functions): For simple types, use functions like [`consensusMedianAggregation()`](#consensusmedianaggregationt).
12080-
2. [**Using field-based aggregation**](/cre/reference/sdk/consensus-ts#2-field-based-aggregation-for-objects): For complex types (objects), use [`ConsensusAggregationByFields()`](#consensusaggregationbyfields).
12080+
2. [**Using field-based aggregation**](/cre/reference/sdk/consensus-ts#2-field-based-aggregation-for-objects): For complex types (objects), use [`ConsensusAggregationByFields()`](#consensusaggregationbyfieldstfields).
1208112081

1208212082
## 1. Built-in aggregation functions
1208312083

@@ -13213,6 +13213,86 @@ function hexToBase64(hex: Hex): string
1321313213

1321413214
***
1321513215

13216+
### `protoBigIntToBigint()`
13217+
13218+
Converts a protobuf `BigInt` (returned by SDK methods like `headerByNumber`) to a native JavaScript `bigint`. Use this when you need to perform arithmetic on block numbers or other numeric values returned from the blockchain.
13219+
13220+
**Signature:**
13221+
13222+
```typescript
13223+
function protoBigIntToBigint(pb: ProtoBigInt): bigint
13224+
```
13225+
13226+
**Parameters:**
13227+
13228+
- `pb`: A protobuf `BigInt` object with `absVal` (Uint8Array) and `sign` (bigint) fields
13229+
13230+
**Returns:**
13231+
13232+
A native JavaScript `bigint` value.
13233+
13234+
**Usage:**
13235+
13236+
```typescript
13237+
import { protoBigIntToBigint } from "@chainlink/cre-sdk"
13238+
13239+
// Get the latest block number from the blockchain
13240+
const latestHeader = evmClient.headerByNumber(runtime, {}).result()
13241+
13242+
// Convert the protobuf BigInt to a native bigint for arithmetic
13243+
const latestBlockNum = protoBigIntToBigint(latestHeader.header.blockNumber)
13244+
const customBlock = latestBlockNum - 500n // Now you can do arithmetic
13245+
13246+
console.log(`Latest block: ${latestBlockNum}`)
13247+
console.log(`Custom block (500 blocks ago): ${customBlock}`)
13248+
```
13249+
13250+
See [Custom Block Depths](/cre/guides/workflow/using-evm-client/onchain-read-ts#custom-block-depths) for a complete example.
13251+
13252+
***
13253+
13254+
### `blockNumber()`
13255+
13256+
Converts a native `bigint`, `number`, or `string` to the protobuf `BigInt` JSON format required by SDK methods. This is a convenience alias for `bigintToProtoBigInt`. Use this when specifying an explicit block height for contract calls or other blockchain queries.
13257+
13258+
**Signature:**
13259+
13260+
```typescript
13261+
function blockNumber(n: number | bigint | string): BigIntJson
13262+
```
13263+
13264+
**Parameters:**
13265+
13266+
- `n`: The block number as a native `bigint`, `number`, or `string`
13267+
13268+
**Returns:**
13269+
13270+
A `BigIntJson` object in the protobuf format expected by SDK methods.
13271+
13272+
**Usage:**
13273+
13274+
```typescript
13275+
import { blockNumber, encodeCallMsg } from "@chainlink/cre-sdk"
13276+
import { zeroAddress } from "viem"
13277+
13278+
// Read from a specific historical block
13279+
const historicalBlock = 9767655n
13280+
const contractCall = evmClient
13281+
.callContract(runtime, {
13282+
call: encodeCallMsg({
13283+
from: zeroAddress,
13284+
to: contractAddress,
13285+
data: callData,
13286+
}),
13287+
blockNumber: blockNumber(historicalBlock),
13288+
})
13289+
.result()
13290+
```
13291+
13292+
See [Custom Block Depths](/cre/guides/workflow/using-evm-client/onchain-read-ts#custom-block-depths) for a complete example.
13293+
13294+
***
13295+
1321613296
### `prepareReportRequest()`
1321713297

1321813298
Prepares a report request with default EVM encoding parameters for use with `runtime.report()`. This helper simplifies report generation by automatically setting the standard encoding configuration (`evm`, `ecdsa`, `keccak256`) required for EVM-based workflows.
@@ -14039,8 +14119,8 @@ const reserveInfo = httpClient
1403914119
Source: https://docs.chain.link/cre/reference/sdk/overview-ts
1404014120
Last Updated: 2025-11-04
1404114121

14042-
<Aside type="note" title="Required SDK Version: v1.0.0">
14043-
The CRE CLI automatically includes version `v1.0.0` of the `@chainlink/cre-sdk` package when you initialize a new
14122+
<Aside type="note" title="Required SDK Version: v1.0.1">
14123+
The CRE CLI automatically includes version `v1.0.1` of the `@chainlink/cre-sdk` package when you initialize a new
1404414124
TypeScript workflow with `cre init`.
1404514125
</Aside>
1404614126

@@ -14845,7 +14925,7 @@ Now you are ready to compile and run the workflow. The single `main.ts` file you
1484514925
<Aside type="note" title="Onchain Writes are Dry Runs by Default">
1484614926
The `--broadcast` flag is included here because this workflow performs an onchain write. By default, the `simulate`
1484714927
command performs a dry run and will not broadcast the transaction without this flag. For more details, see the `cre
14848-
workflow simulate` [reference](/cre/reference/cli#cre-workflow-simulate).
14928+
workflow simulate` [reference](/cre/reference/cli/workflow#cre-workflow-simulate).
1484914929
</Aside>
1485014930

1485114931
You will first see a `Workflow compiled` message, followed by the trigger selection menu.

src/content/cre/reference/sdk/evm-client-ts.mdx

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,86 @@ function hexToBase64(hex: Hex): string
559559

560560
---
561561

562+
### `protoBigIntToBigint()`
563+
564+
Converts a protobuf `BigInt` (returned by SDK methods like `headerByNumber`) to a native JavaScript `bigint`. Use this when you need to perform arithmetic on block numbers or other numeric values returned from the blockchain.
565+
566+
**Signature:**
567+
568+
```typescript
569+
function protoBigIntToBigint(pb: ProtoBigInt): bigint
570+
```
571+
572+
**Parameters:**
573+
574+
- `pb`: A protobuf `BigInt` object with `absVal` (Uint8Array) and `sign` (bigint) fields
575+
576+
**Returns:**
577+
578+
A native JavaScript `bigint` value.
579+
580+
**Usage:**
581+
582+
```typescript
583+
import { protoBigIntToBigint } from "@chainlink/cre-sdk"
584+
585+
// Get the latest block number from the blockchain
586+
const latestHeader = evmClient.headerByNumber(runtime, {}).result()
587+
588+
// Convert the protobuf BigInt to a native bigint for arithmetic
589+
const latestBlockNum = protoBigIntToBigint(latestHeader.header.blockNumber)
590+
const customBlock = latestBlockNum - 500n // Now you can do arithmetic
591+
592+
console.log(`Latest block: ${latestBlockNum}`)
593+
console.log(`Custom block (500 blocks ago): ${customBlock}`)
594+
```
595+
596+
See [Custom Block Depths](/cre/guides/workflow/using-evm-client/onchain-read-ts#custom-block-depths) for a complete example.
597+
598+
---
599+
600+
### `blockNumber()`
601+
602+
Converts a native `bigint`, `number`, or `string` to the protobuf `BigInt` JSON format required by SDK methods. This is a convenience alias for `bigintToProtoBigInt`. Use this when specifying an explicit block height for contract calls or other blockchain queries.
603+
604+
**Signature:**
605+
606+
```typescript
607+
function blockNumber(n: number | bigint | string): BigIntJson
608+
```
609+
610+
**Parameters:**
611+
612+
- `n`: The block number as a native `bigint`, `number`, or `string`
613+
614+
**Returns:**
615+
616+
A `BigIntJson` object in the protobuf format expected by SDK methods.
617+
618+
**Usage:**
619+
620+
```typescript
621+
import { blockNumber, encodeCallMsg } from "@chainlink/cre-sdk"
622+
import { zeroAddress } from "viem"
623+
624+
// Read from a specific historical block
625+
const historicalBlock = 9767655n
626+
const contractCall = evmClient
627+
.callContract(runtime, {
628+
call: encodeCallMsg({
629+
from: zeroAddress,
630+
to: contractAddress,
631+
data: callData,
632+
}),
633+
blockNumber: blockNumber(historicalBlock),
634+
})
635+
.result()
636+
```
637+
638+
See [Custom Block Depths](/cre/guides/workflow/using-evm-client/onchain-read-ts#custom-block-depths) for a complete example.
639+
640+
---
641+
562642
### `prepareReportRequest()`
563643

564644
Prepares a report request with default EVM encoding parameters for use with `runtime.report()`. This helper simplifies report generation by automatically setting the standard encoding configuration (`evm`, `ecdsa`, `keccak256`) required for EVM-based workflows.

src/content/cre/reference/sdk/overview-ts.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ metadata:
1212

1313
import { Aside } from "@components"
1414

15-
<Aside type="note" title="Required SDK Version: v1.0.0">
16-
The CRE CLI automatically includes version `v1.0.0` of the `@chainlink/cre-sdk` package when you initialize a new
15+
<Aside type="note" title="Required SDK Version: v1.0.1">
16+
The CRE CLI automatically includes version `v1.0.1` of the `@chainlink/cre-sdk` package when you initialize a new
1717
TypeScript workflow with `cre init`.
1818
</Aside>
1919

src/content/data-feeds/llms-full.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4151,7 +4151,7 @@ starkli --version
41514151
0.2.8 (f59724e)
41524152
```
41534153

4154-
Follow the official [installation guide]((https://book.starkli.rs/installation)) if necessary.
4154+
Follow the official [installation guide](https://book.starkli.rs/installation) if necessary.
41554155

41564156
### Read data from a Chainlink Price Feed
41574157

0 commit comments

Comments
 (0)