genlayer-js 0.15.0 → 0.16.0

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,19 @@
1
1
 
2
2
 
3
+ ## 0.16.0 (2025-09-03)
4
+
5
+
6
+ ### Features
7
+
8
+ * **contracts,types:** add getContractCode via gen_getContractCode RPC ([#109](https://github.com/genlayerlabs/genlayer-js/issues/109)) ([3fcc934](https://github.com/genlayerlabs/genlayer-js/commit/3fcc934a73b312747d53831f63d8c2e903534b3f))
9
+
10
+ ## 0.15.1 (2025-09-02)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **client:** disable viem transport retries (retryCount=0) to avoid duplicate requests ([#110](https://github.com/genlayerlabs/genlayer-js/issues/110)) ([dc2d623](https://github.com/genlayerlabs/genlayer-js/commit/dc2d623bb0a2bf96416e1590ddbcbf78adf9f9a7))
16
+
3
17
  ## 0.15.0 (2025-08-18)
4
18
 
5
19
 
@@ -304,6 +304,9 @@ type GenLayerMethod = {
304
304
  } | {
305
305
  method: "gen_getContractSchemaForCode";
306
306
  params: [contractCode: string];
307
+ } | {
308
+ method: "gen_getContractCode";
309
+ params: [address: Address];
307
310
  } | {
308
311
  method: "sim_getTransactionsForAddress";
309
312
  params: [address: Address, filter?: "all" | "from" | "to"];
@@ -367,6 +370,7 @@ type GenLayerClient<TGenLayerChain extends GenLayerChain> = Omit<Client<Transpor
367
370
  }) => Promise<GenLayerTransaction>;
368
371
  getContractSchema: (address: Address) => Promise<ContractSchema>;
369
372
  getContractSchemaForCode: (contractCode: string | Uint8Array) => Promise<ContractSchema>;
373
+ getContractCode: (address: Address) => Promise<string>;
370
374
  initializeConsensusSmartContract: (forceReset?: boolean) => Promise<void>;
371
375
  connect: (network?: Network, snapSource?: SnapSource) => Promise<void>;
372
376
  metamaskClient: (snapSource?: SnapSource) => Promise<MetaMaskClientResult>;
@@ -304,6 +304,9 @@ type GenLayerMethod = {
304
304
  } | {
305
305
  method: "gen_getContractSchemaForCode";
306
306
  params: [contractCode: string];
307
+ } | {
308
+ method: "gen_getContractCode";
309
+ params: [address: Address];
307
310
  } | {
308
311
  method: "sim_getTransactionsForAddress";
309
312
  params: [address: Address, filter?: "all" | "from" | "to"];
@@ -367,6 +370,7 @@ type GenLayerClient<TGenLayerChain extends GenLayerChain> = Omit<Client<Transpor
367
370
  }) => Promise<GenLayerTransaction>;
368
371
  getContractSchema: (address: Address) => Promise<ContractSchema>;
369
372
  getContractSchemaForCode: (contractCode: string | Uint8Array) => Promise<ContractSchema>;
373
+ getContractCode: (address: Address) => Promise<string>;
370
374
  initializeConsensusSmartContract: (forceReset?: boolean) => Promise<void>;
371
375
  connect: (network?: Network, snapSource?: SnapSource) => Promise<void>;
372
376
  metamaskClient: (snapSource?: SnapSource) => Promise<MetaMaskClientResult>;
package/dist/index.cjs CHANGED
@@ -408,8 +408,70 @@ function serialize(data) {
408
408
 
409
409
  // src/contracts/actions.ts
410
410
 
411
+
412
+ // src/abi/index.ts
413
+ var abi_exports = {};
414
+ _chunk75ZPJI57cjs.__export.call(void 0, abi_exports, {
415
+ calldata: () => calldata,
416
+ transactions: () => transactions
417
+ });
418
+ var calldata = calldata_exports;
419
+ var transactions = transactions_exports;
420
+
421
+ // src/utils/jsonifier.ts
422
+ function b64ToArray(b64) {
423
+ return Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
424
+ }
425
+ function calldataToUserFriendlyJson(cd) {
426
+ return {
427
+ raw: Array.from(cd),
428
+ readable: calldata.toString(calldata.decode(cd))
429
+ };
430
+ }
431
+ var RESULT_CODES = /* @__PURE__ */ new Map([
432
+ [0, "return"],
433
+ [1, "rollback"],
434
+ [2, "contract_error"],
435
+ [3, "error"],
436
+ [4, "none"],
437
+ [5, "no_leaders"]
438
+ ]);
439
+ function resultToUserFriendlyJson(cd64) {
440
+ const raw = b64ToArray(cd64);
441
+ const code = RESULT_CODES.get(raw[0]);
442
+ let status;
443
+ let payload = null;
444
+ if (code === void 0) {
445
+ status = "<unknown>";
446
+ } else {
447
+ status = code;
448
+ if ([1, 2].includes(raw[0])) {
449
+ payload = new TextDecoder("utf-8").decode(raw.slice(1));
450
+ } else if (raw[0] == 0) {
451
+ payload = calldataToUserFriendlyJson(raw.slice(1));
452
+ }
453
+ }
454
+ return {
455
+ raw: cd64,
456
+ status,
457
+ payload
458
+ };
459
+ }
460
+
461
+ // src/contracts/actions.ts
411
462
  var contractActions = (client, publicClient) => {
412
463
  return {
464
+ getContractCode: async (address) => {
465
+ if (client.chain.id !== _chunkZKBMABRAcjs.localnet.id) {
466
+ throw new Error("Getting contract code is not supported on this network");
467
+ }
468
+ const result = await client.request({
469
+ method: "gen_getContractCode",
470
+ params: [address]
471
+ });
472
+ const codeBytes = b64ToArray(result);
473
+ return new TextDecoder().decode(codeBytes);
474
+ },
413
475
  getContractSchema: async (address) => {
414
476
  if (client.chain.id !== _chunkZKBMABRAcjs.localnet.id) {
415
477
  throw new Error("Contract schema is not supported on this network");
@@ -636,55 +698,6 @@ async function sleep(ms) {
636
698
  return new Promise((resolve) => setTimeout(resolve, ms));
637
699
  }
638
700
 
639
- // src/abi/index.ts
640
- var abi_exports = {};
641
- _chunk75ZPJI57cjs.__export.call(void 0, abi_exports, {
642
- calldata: () => calldata,
643
- transactions: () => transactions
644
- });
645
- var calldata = calldata_exports;
646
- var transactions = transactions_exports;
647
-
648
- // src/utils/jsonifier.ts
649
- function b64ToArray(b64) {
650
- return Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
651
- }
652
- function calldataToUserFriendlyJson(cd) {
653
- return {
654
- raw: Array.from(cd),
655
- readable: calldata.toString(calldata.decode(cd))
656
- };
657
- }
658
- var RESULT_CODES = /* @__PURE__ */ new Map([
659
- [0, "return"],
660
- [1, "rollback"],
661
- [2, "contract_error"],
662
- [3, "error"],
663
- [4, "none"],
664
- [5, "no_leaders"]
665
- ]);
666
- function resultToUserFriendlyJson(cd64) {
667
- const raw = b64ToArray(cd64);
668
- const code = RESULT_CODES.get(raw[0]);
669
- let status;
670
- let payload = null;
671
- if (code === void 0) {
672
- status = "<unknown>";
673
- } else {
674
- status = code;
675
- if ([1, 2].includes(raw[0])) {
676
- payload = new TextDecoder("utf-8").decode(raw.slice(1));
677
- } else if (raw[0] == 0) {
678
- payload = calldataToUserFriendlyJson(raw.slice(1));
679
- }
680
- }
681
- return {
682
- raw: cd64,
683
- status,
684
- payload
685
- };
686
- }
687
-
688
701
  // src/transactions/decoders.ts
689
702
 
690
703
  var FIELDS_TO_REMOVE = [
@@ -1171,7 +1184,7 @@ var createClient = (config = { chain: _chunkZKBMABRAcjs.localnet }) => {
1171
1184
  if (config.endpoint) {
1172
1185
  chainConfig.rpcUrls.default.http = [config.endpoint];
1173
1186
  }
1174
- const customTransport = _viem.custom.call(void 0, getCustomTransportConfig(config));
1187
+ const customTransport = _viem.custom.call(void 0, getCustomTransportConfig(config), { retryCount: 0, retryDelay: 0 });
1175
1188
  const publicClient = createPublicClient(chainConfig, customTransport).extend(
1176
1189
  _viem.publicActions
1177
1190
  );
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as viem from 'viem';
2
2
  import { Account, Address, Hex } from 'viem';
3
3
  import { G as GenLayerChain } from './chains-BYSCF33g.cjs';
4
- import { G as GenLayerClient, D as DecodedDeployData, a as DecodedCallData, b as GenLayerRawTransaction, c as GenLayerTransaction, C as CalldataEncodable, T as TransactionDataElement } from './index-IViMPpkl.cjs';
4
+ import { G as GenLayerClient, D as DecodedDeployData, a as DecodedCallData, b as GenLayerRawTransaction, c as GenLayerTransaction, C as CalldataEncodable, T as TransactionDataElement } from './index-DQUXmYng.cjs';
5
5
  import * as abitype from 'abitype';
6
6
  import * as viem__types_types_authorization from 'viem/_types/types/authorization';
7
7
  import * as viem_accounts from 'viem/accounts';
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as viem from 'viem';
2
2
  import { Account, Address, Hex } from 'viem';
3
3
  import { G as GenLayerChain } from './chains-BYSCF33g.js';
4
- import { G as GenLayerClient, D as DecodedDeployData, a as DecodedCallData, b as GenLayerRawTransaction, c as GenLayerTransaction, C as CalldataEncodable, T as TransactionDataElement } from './index-CgHl4W-5.js';
4
+ import { G as GenLayerClient, D as DecodedDeployData, a as DecodedCallData, b as GenLayerRawTransaction, c as GenLayerTransaction, C as CalldataEncodable, T as TransactionDataElement } from './index-DVMV4wM0.js';
5
5
  import * as abitype from 'abitype';
6
6
  import * as viem__types_types_authorization from 'viem/_types/types/authorization';
7
7
  import * as viem_accounts from 'viem/accounts';
package/dist/index.js CHANGED
@@ -408,8 +408,70 @@ function serialize(data) {
408
408
 
409
409
  // src/contracts/actions.ts
410
410
  import { fromHex, toHex as toHex2, zeroAddress, encodeFunctionData, parseEventLogs } from "viem";
411
+
412
+ // src/abi/index.ts
413
+ var abi_exports = {};
414
+ __export(abi_exports, {
415
+ calldata: () => calldata,
416
+ transactions: () => transactions
417
+ });
418
+ var calldata = calldata_exports;
419
+ var transactions = transactions_exports;
420
+
421
+ // src/utils/jsonifier.ts
422
+ function b64ToArray(b64) {
423
+ return Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
424
+ }
425
+ function calldataToUserFriendlyJson(cd) {
426
+ return {
427
+ raw: Array.from(cd),
428
+ readable: calldata.toString(calldata.decode(cd))
429
+ };
430
+ }
431
+ var RESULT_CODES = /* @__PURE__ */ new Map([
432
+ [0, "return"],
433
+ [1, "rollback"],
434
+ [2, "contract_error"],
435
+ [3, "error"],
436
+ [4, "none"],
437
+ [5, "no_leaders"]
438
+ ]);
439
+ function resultToUserFriendlyJson(cd64) {
440
+ const raw = b64ToArray(cd64);
441
+ const code = RESULT_CODES.get(raw[0]);
442
+ let status;
443
+ let payload = null;
444
+ if (code === void 0) {
445
+ status = "<unknown>";
446
+ } else {
447
+ status = code;
448
+ if ([1, 2].includes(raw[0])) {
449
+ payload = new TextDecoder("utf-8").decode(raw.slice(1));
450
+ } else if (raw[0] == 0) {
451
+ payload = calldataToUserFriendlyJson(raw.slice(1));
452
+ }
453
+ }
454
+ return {
455
+ raw: cd64,
456
+ status,
457
+ payload
458
+ };
459
+ }
460
+
461
+ // src/contracts/actions.ts
411
462
  var contractActions = (client, publicClient) => {
412
463
  return {
464
+ getContractCode: async (address) => {
465
+ if (client.chain.id !== localnet.id) {
466
+ throw new Error("Getting contract code is not supported on this network");
467
+ }
468
+ const result = await client.request({
469
+ method: "gen_getContractCode",
470
+ params: [address]
471
+ });
472
+ const codeBytes = b64ToArray(result);
473
+ return new TextDecoder().decode(codeBytes);
474
+ },
413
475
  getContractSchema: async (address) => {
414
476
  if (client.chain.id !== localnet.id) {
415
477
  throw new Error("Contract schema is not supported on this network");
@@ -636,55 +698,6 @@ async function sleep(ms) {
636
698
  return new Promise((resolve) => setTimeout(resolve, ms));
637
699
  }
638
700
 
639
- // src/abi/index.ts
640
- var abi_exports = {};
641
- __export(abi_exports, {
642
- calldata: () => calldata,
643
- transactions: () => transactions
644
- });
645
- var calldata = calldata_exports;
646
- var transactions = transactions_exports;
647
-
648
- // src/utils/jsonifier.ts
649
- function b64ToArray(b64) {
650
- return Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
651
- }
652
- function calldataToUserFriendlyJson(cd) {
653
- return {
654
- raw: Array.from(cd),
655
- readable: calldata.toString(calldata.decode(cd))
656
- };
657
- }
658
- var RESULT_CODES = /* @__PURE__ */ new Map([
659
- [0, "return"],
660
- [1, "rollback"],
661
- [2, "contract_error"],
662
- [3, "error"],
663
- [4, "none"],
664
- [5, "no_leaders"]
665
- ]);
666
- function resultToUserFriendlyJson(cd64) {
667
- const raw = b64ToArray(cd64);
668
- const code = RESULT_CODES.get(raw[0]);
669
- let status;
670
- let payload = null;
671
- if (code === void 0) {
672
- status = "<unknown>";
673
- } else {
674
- status = code;
675
- if ([1, 2].includes(raw[0])) {
676
- payload = new TextDecoder("utf-8").decode(raw.slice(1));
677
- } else if (raw[0] == 0) {
678
- payload = calldataToUserFriendlyJson(raw.slice(1));
679
- }
680
- }
681
- return {
682
- raw: cd64,
683
- status,
684
- payload
685
- };
686
- }
687
-
688
701
  // src/transactions/decoders.ts
689
702
  import { fromRlp, fromHex as fromHex2 } from "viem";
690
703
  var FIELDS_TO_REMOVE = [
@@ -1171,7 +1184,7 @@ var createClient = (config = { chain: localnet }) => {
1171
1184
  if (config.endpoint) {
1172
1185
  chainConfig.rpcUrls.default.http = [config.endpoint];
1173
1186
  }
1174
- const customTransport = custom(getCustomTransportConfig(config));
1187
+ const customTransport = custom(getCustomTransportConfig(config), { retryCount: 0, retryDelay: 0 });
1175
1188
  const publicClient = createPublicClient(chainConfig, customTransport).extend(
1176
1189
  publicActions
1177
1190
  );
@@ -1,3 +1,3 @@
1
1
  export { Account, Address } from 'viem';
2
- export { d as CalldataAddress, C as CalldataEncodable, i as ContractMethod, h as ContractMethodBase, f as ContractParamsArraySchemaElement, g as ContractParamsSchema, j as ContractSchema, a as DecodedCallData, D as DecodedDeployData, G as GenLayerClient, e as GenLayerMethod, b as GenLayerRawTransaction, c as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, S as SnapSource, k as TransactionHash, s as TransactionHashVariant, m as TransactionResult, p as TransactionResultNameToNumber, l as TransactionStatus, r as TransactionType, V as VoteType, o as transactionResultNumberToName, n as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, q as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-IViMPpkl.cjs';
2
+ export { d as CalldataAddress, C as CalldataEncodable, i as ContractMethod, h as ContractMethodBase, f as ContractParamsArraySchemaElement, g as ContractParamsSchema, j as ContractSchema, a as DecodedCallData, D as DecodedDeployData, G as GenLayerClient, e as GenLayerMethod, b as GenLayerRawTransaction, c as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, S as SnapSource, k as TransactionHash, s as TransactionHashVariant, m as TransactionResult, p as TransactionResultNameToNumber, l as TransactionStatus, r as TransactionType, V as VoteType, o as transactionResultNumberToName, n as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, q as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-DQUXmYng.cjs';
3
3
  export { G as GenLayerChain } from '../chains-BYSCF33g.cjs';
@@ -1,3 +1,3 @@
1
1
  export { Account, Address } from 'viem';
2
- export { d as CalldataAddress, C as CalldataEncodable, i as ContractMethod, h as ContractMethodBase, f as ContractParamsArraySchemaElement, g as ContractParamsSchema, j as ContractSchema, a as DecodedCallData, D as DecodedDeployData, G as GenLayerClient, e as GenLayerMethod, b as GenLayerRawTransaction, c as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, S as SnapSource, k as TransactionHash, s as TransactionHashVariant, m as TransactionResult, p as TransactionResultNameToNumber, l as TransactionStatus, r as TransactionType, V as VoteType, o as transactionResultNumberToName, n as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, q as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-CgHl4W-5.js';
2
+ export { d as CalldataAddress, C as CalldataEncodable, i as ContractMethod, h as ContractMethodBase, f as ContractParamsArraySchemaElement, g as ContractParamsSchema, j as ContractSchema, a as DecodedCallData, D as DecodedDeployData, G as GenLayerClient, e as GenLayerMethod, b as GenLayerRawTransaction, c as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, S as SnapSource, k as TransactionHash, s as TransactionHashVariant, m as TransactionResult, p as TransactionResultNameToNumber, l as TransactionStatus, r as TransactionType, V as VoteType, o as transactionResultNumberToName, n as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, q as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-DVMV4wM0.js';
3
3
  export { G as GenLayerChain } from '../chains-BYSCF33g.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "genlayer-js",
3
3
  "type": "module",
4
- "version": "0.15.0",
4
+ "version": "0.16.0",
5
5
  "description": "GenLayer JavaScript SDK",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -89,7 +89,7 @@ export const createClient = (config: ClientConfig = {chain: localnet}): GenLayer
89
89
  chainConfig.rpcUrls.default.http = [config.endpoint];
90
90
  }
91
91
 
92
- const customTransport = custom(getCustomTransportConfig(config));
92
+ const customTransport = custom(getCustomTransportConfig(config), {retryCount: 0, retryDelay: 0});
93
93
  const publicClient = createPublicClient(chainConfig as GenLayerChain, customTransport).extend(
94
94
  publicActions,
95
95
  );
@@ -11,9 +11,21 @@ import {
11
11
  TransactionHashVariant,
12
12
  } from "@/types";
13
13
  import {fromHex, toHex, zeroAddress, encodeFunctionData, PublicClient, parseEventLogs} from "viem";
14
+ import {b64ToArray} from "@/utils/jsonifier";
14
15
 
15
16
  export const contractActions = (client: GenLayerClient<GenLayerChain>, publicClient: PublicClient) => {
16
17
  return {
18
+ getContractCode: async (address: Address): Promise<string> => {
19
+ if (client.chain.id !== localnet.id) {
20
+ throw new Error("Getting contract code is not supported on this network");
21
+ }
22
+ const result = (await client.request({
23
+ method: "gen_getContractCode",
24
+ params: [address],
25
+ })) as string;
26
+ const codeBytes = b64ToArray(result);
27
+ return new TextDecoder().decode(codeBytes);
28
+ },
17
29
  getContractSchema: async (address: Address): Promise<ContractSchema> => {
18
30
  if (client.chain.id !== localnet.id) {
19
31
  throw new Error("Contract schema is not supported on this network");
@@ -15,6 +15,7 @@ export type GenLayerMethod =
15
15
  | {method: "eth_sendRawTransaction"; params: [signedTransaction: string]}
16
16
  | {method: "gen_getContractSchema"; params: [address: Address]}
17
17
  | {method: "gen_getContractSchemaForCode"; params: [contractCode: string]}
18
+ | {method: "gen_getContractCode"; params: [address: Address]}
18
19
  | {method: "sim_getTransactionsForAddress"; params: [address: Address, filter?: "all" | "from" | "to"]}
19
20
  | {method: "eth_getTransactionCount"; params: [address: Address, block: string]}
20
21
  | {method: "gen_call"; params: [requestParams: any]};
@@ -76,6 +77,7 @@ export type GenLayerClient<TGenLayerChain extends GenLayerChain> = Omit<
76
77
  }) => Promise<GenLayerTransaction>;
77
78
  getContractSchema: (address: Address) => Promise<ContractSchema>;
78
79
  getContractSchemaForCode: (contractCode: string | Uint8Array) => Promise<ContractSchema>;
80
+ getContractCode: (address: Address) => Promise<string>;
79
81
  initializeConsensusSmartContract: (forceReset?: boolean) => Promise<void>;
80
82
  connect: (network?: Network, snapSource?: SnapSource) => Promise<void>;
81
83
  metamaskClient: (snapSource?: SnapSource) => Promise<MetaMaskClientResult>;