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
1.**Protobuf `BigInt` to native `bigint`:**The `protoBigIntToBigInt` helper converts the SDK's protobuf `BigInt` type (which stores the value as `absVal: Uint8Array`) to JavaScript's native `bigint`. This allows you to perform arithmetic like subtracting 500 blocks.
229
+
The SDK provides two helper functions for working with block numbers:
237
230
238
-
1.**Native `bigint` to `BigIntJson`:** To pass a native `bigint` back to the SDK:
239
-
-`blockNum.toString(16)` converts to hexadecimal
240
-
-`.padStart(2, '0')` ensures even-length hex string (required by `Buffer.from`)
241
-
-`Buffer.from(..., 'hex')` creates a byte array from the hex
242
-
-`.toString('base64')` converts to base64 format required by `BigIntJson.absVal`
231
+
-**`protoBigIntToBigint(pb)`** — 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.
The SDK team is working on built-in helpers for both conversions (protobuf `BigInt` ↔ native `bigint` and `bigint` →
246
-
`BigIntJson`). Until then, use the patterns shown above.
247
-
</Aside>
233
+
-**`blockNumber(n)`** — Converts a native `bigint`, `number`, or `string` to the protobuf `BigInt` JSON format required by SDK methods. This is an alias for `bigintToProtoBigInt`.
248
234
249
235
See [Finality and Confidence Levels](/cre/concepts/finality-ts) for more details on when to use custom block depths.
1. **Protobuf `BigInt` to native `bigint`:** The `protoBigIntToBigInt` helper converts the SDK's protobuf `BigInt` type (which stores the value as `absVal: Uint8Array`) to JavaScript's native `bigint`. This allows you to perform arithmetic like subtracting 500 blocks.
9085
+
The SDK provides two helper functions for working with block numbers:
9093
9086
9094
-
2. **Native `bigint` to `BigIntJson`:** To pass a native `bigint` back to the SDK:
9095
-
- `blockNum.toString(16)` converts to hexadecimal
9096
-
- `.padStart(2, '0')` ensures even-length hex string (required by `Buffer.from`)
9097
-
- `Buffer.from(..., 'hex')` creates a byte array from the hex
9098
-
- `.toString('base64')` converts to base64 format required by `BigIntJson.absVal`
9087
+
- **`protoBigIntToBigint(pb)`** — 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.
The SDK team is working on built-in helpers for both conversions (protobuf `BigInt` ↔ native `bigint` and `bigint` →
9102
-
`BigIntJson`). Until then, use the patterns shown above.
9103
-
</Aside>
9089
+
- **`blockNumber(n)`** — Converts a native `bigint`, `number`, or `string` to the protobuf `BigInt` JSON format required by SDK methods. This is an alias for `bigintToProtoBigInt`.
9104
9090
9105
9091
See [Finality and Confidence Levels](/cre/concepts/finality-ts) for more details on when to use custom block depths.
0 commit comments