genlayer 0.38.10 → 0.38.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.38.12 (2026-04-01)
4
+
5
+ ## 0.38.11 (2026-04-01)
6
+
7
+ ### Bug Fixes
8
+
9
+ * work around GenLayer RPC rejecting JSON-RPC id=0 ([74b71ab](https://github.com/genlayerlabs/genlayer-cli/commit/74b71ab91a6e80343d5d1560fcacbe37f74bac64))
10
+
3
11
  ## 0.38.10 (2026-03-31)
4
12
 
5
13
  ### Bug Fixes
package/dist/index.js CHANGED
@@ -20078,7 +20078,7 @@ var require_cli_table3 = __commonJS({
20078
20078
  import { program } from "commander";
20079
20079
 
20080
20080
  // package.json
20081
- var version = "0.38.10";
20081
+ var version = "0.38.12";
20082
20082
  var package_default = {
20083
20083
  name: "genlayer",
20084
20084
  version,
@@ -56040,6 +56040,16 @@ function initializeTransactionsCommands(program2) {
56040
56040
  // src/commands/staking/StakingAction.ts
56041
56041
  import { readFileSync as readFileSync8, existsSync as existsSync8 } from "fs";
56042
56042
  import { ethers as ethers6, ZeroAddress } from "ethers";
56043
+ var glHttpConfig = {
56044
+ async fetchFn(url, init) {
56045
+ if (init?.body) {
56046
+ const body = JSON.parse(init.body);
56047
+ if (body.id === 0) body.id = 1;
56048
+ init = { ...init, body: JSON.stringify(body) };
56049
+ }
56050
+ return fetch(url, init);
56051
+ }
56052
+ };
56043
56053
  var STAKING_TREE_ABI = [
56044
56054
  {
56045
56055
  name: "validatorsRoot",
@@ -56181,11 +56191,11 @@ var StakingAction = class extends BaseAction {
56181
56191
  const account = privateKeyToAccount(privateKey);
56182
56192
  const publicClient = createPublicClient({
56183
56193
  chain: network,
56184
- transport: http3(rpcUrl)
56194
+ transport: http3(rpcUrl, glHttpConfig)
56185
56195
  });
56186
56196
  const walletClient = createWalletClient({
56187
56197
  chain: network,
56188
- transport: http3(rpcUrl),
56198
+ transport: http3(rpcUrl, glHttpConfig),
56189
56199
  account
56190
56200
  });
56191
56201
  return {
@@ -56207,7 +56217,7 @@ var StakingAction = class extends BaseAction {
56207
56217
  }
56208
56218
  const publicClient = createPublicClient({
56209
56219
  chain: network,
56210
- transport: http3(rpcUrl)
56220
+ transport: http3(rpcUrl, glHttpConfig)
56211
56221
  });
56212
56222
  const root = await publicClient.readContract({
56213
56223
  address: stakingAddress,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "genlayer",
3
- "version": "0.38.10",
3
+ "version": "0.38.12",
4
4
  "description": "GenLayer Command Line Tool",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -3,9 +3,22 @@ import {createClient, createAccount, formatStakingAmount, parseStakingAmount, ab
3
3
  import type {GenLayerClient, GenLayerChain, Address} from "genlayer-js/types";
4
4
  import {readFileSync, existsSync} from "fs";
5
5
  import {ethers, ZeroAddress} from "ethers";
6
- import {createPublicClient, createWalletClient, http, type PublicClient, type WalletClient, type Chain, type Account} from "viem";
6
+ import {createPublicClient, createWalletClient, http, type PublicClient, type WalletClient, type Chain, type Account, type HttpTransportConfig} from "viem";
7
7
  import {privateKeyToAccount} from "viem/accounts";
8
8
 
9
+ // GenLayer RPC rejects JSON-RPC requests with id=0 (treats 0 as missing).
10
+ // Viem starts its id counter at 0, so we ensure non-zero ids.
11
+ const glHttpConfig: HttpTransportConfig = {
12
+ async fetchFn(url, init) {
13
+ if (init?.body) {
14
+ const body = JSON.parse(init.body as string);
15
+ if (body.id === 0) body.id = 1;
16
+ init = {...init, body: JSON.stringify(body)};
17
+ }
18
+ return fetch(url, init);
19
+ },
20
+ };
21
+
9
22
  // Extended ABI for tree traversal (not in SDK)
10
23
  const STAKING_TREE_ABI = [
11
24
  {
@@ -201,12 +214,12 @@ export class StakingAction extends BaseAction {
201
214
 
202
215
  const publicClient = createPublicClient({
203
216
  chain: network,
204
- transport: http(rpcUrl),
217
+ transport: http(rpcUrl, glHttpConfig),
205
218
  });
206
219
 
207
220
  const walletClient = createWalletClient({
208
221
  chain: network,
209
- transport: http(rpcUrl),
222
+ transport: http(rpcUrl, glHttpConfig),
210
223
  account,
211
224
  });
212
225
 
@@ -232,7 +245,7 @@ export class StakingAction extends BaseAction {
232
245
 
233
246
  const publicClient = createPublicClient({
234
247
  chain: network,
235
- transport: http(rpcUrl),
248
+ transport: http(rpcUrl, glHttpConfig),
236
249
  });
237
250
 
238
251
  // Get the root of the validator tree
@@ -1,7 +1,8 @@
1
1
  import {describe, it, expect, beforeAll} from "vitest";
2
- import {createClient, parseStakingAmount, formatStakingAmount} from "genlayer-js";
2
+ import {createClient, parseStakingAmount, formatStakingAmount, abi} from "genlayer-js";
3
3
  import {testnetAsimov, testnetBradbury} from "genlayer-js/chains";
4
4
  import type {Address, GenLayerChain} from "genlayer-js/types";
5
+ import {createPublicClient, http} from "viem";
5
6
 
6
7
  const TIMEOUT = 30_000;
7
8
 
@@ -120,6 +121,36 @@ describe(`Testnet ${name} - CLI Staking Smoke Tests`, () => {
120
121
  }
121
122
  }, TIMEOUT);
122
123
 
124
+ it("viem createPublicClient can call staking contract directly", async () => {
125
+ const rpcUrl = chain.rpcUrls.default.http[0];
126
+ const stakingAddress = chain.stakingContract?.address;
127
+ if (!stakingAddress) return;
128
+
129
+ // Use the same id-fix workaround as StakingAction (GenLayer RPC rejects id=0)
130
+ const publicClient = createPublicClient({
131
+ chain,
132
+ transport: http(rpcUrl, {
133
+ async fetchFn(url, init) {
134
+ if (init?.body) {
135
+ const body = JSON.parse(init.body as string);
136
+ if (body.id === 0) body.id = 1;
137
+ init = {...init, body: JSON.stringify(body)};
138
+ }
139
+ return fetch(url, init);
140
+ },
141
+ }),
142
+ });
143
+
144
+ const count = await publicClient.readContract({
145
+ address: stakingAddress as `0x${string}`,
146
+ abi: abi.STAKING_ABI,
147
+ functionName: "activeValidatorsCount",
148
+ });
149
+
150
+ expect(typeof count).toBe("bigint");
151
+ expect(count as bigint >= 0n).toBe(true);
152
+ }, TIMEOUT);
153
+
123
154
  it("parseStakingAmount and formatStakingAmount round-trip", () => {
124
155
  const parsed = parseStakingAmount("1.5gen");
125
156
  expect(typeof parsed).toBe("bigint");