You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| [**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 |
11644
11644
| [**Pattern 3: Report in body, signatures in headers**](#pattern-3-report-in-body-signatures-in-headers) | Your API needs signatures separated for easier parsing |
11645
11645
| [**Pattern 4: JSON-formatted report**](#pattern-4-json-formatted-report) | Your API only accepts JSON payloads |
// The payload.Input is []byte containing JSON data.
12713
12713
// Unmarshal it into a map or a custom struct.
12714
-
var requestData map[string]interface{}
12714
+
var requestData map[string]any
12715
12715
if err := json.Unmarshal(payload.Input, &requestData); err != nil {
12716
12716
return nil, fmt.Errorf("failed to unmarshal input: %w", err)
12717
12717
}
@@ -13211,8 +13211,8 @@ This is a generic interface passed as the final argument to `cre.RunInNodeMode`.
13211
13211
13212
13212
There are two primary ways to specify an aggregation method:
13213
13213
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).
13216
13216
13217
13217
## 1. Built-in aggregation functions
13218
13218
@@ -13368,7 +13368,7 @@ These interfaces provide access to capabilities and manage the execution context
13368
13368
13369
13369
- **`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.
13370
13370
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.
13372
13372
13373
13373
To learn more about how to aggregate results from `NodeRuntime`, see the [Consensus & Aggregation](/cre/reference/sdk/consensus) reference.
13374
13374
@@ -14638,7 +14638,7 @@ Now you are ready to compile and run the workflow. The workflow code (`workflow.
14638
14638
<Aside type="note" title="Onchain Writes are Dry Runs by Default">
14639
14639
The `--broadcast` flag is included here because this workflow performs an onchain write. By default, the `simulate`
14640
14640
command performs a dry run and will not broadcast the transaction without this flag. For more details, see the `cre
| [**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 |
10448
10448
| [**Pattern 3: Report in body, signatures in headers**](#pattern-3-report-in-body-signatures-in-headers) | Your API needs signatures separated for easier parsing |
10449
10449
| [**Pattern 4: JSON-formatted report**](#pattern-4-json-formatted-report) | Your API only accepts JSON payloads |
10450
10450
@@ -12077,7 +12077,7 @@ This is a generic type passed as the second argument to `runtime.runInNodeMode()
12077
12077
There are two primary ways to specify an aggregation method:
12078
12078
12079
12079
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).
12081
12081
12082
12082
## 1. Built-in aggregation functions
12083
12083
@@ -13213,6 +13213,86 @@ function hexToBase64(hex: Hex): string
13213
13213
13214
13214
***
13215
13215
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
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
+
13216
13296
### `prepareReportRequest()`
13217
13297
13218
13298
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.
0 commit comments