genlayer-js 0.6.4 → 0.8.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 +14 -0
- package/README.md +6 -6
- package/dist/chains/index.cjs +4 -2
- package/dist/chains/index.d.cts +1 -1
- package/dist/chains/index.d.ts +1 -1
- package/dist/chains/index.js +3 -1
- package/dist/{chunk-XAQMWSP4.cjs → chunk-I6HC44KD.cjs} +34 -4
- package/dist/{chunk-O3T2C57T.js → chunk-WEXFFND6.js} +33 -3
- package/dist/index-B8E0qiOq.d.cts +13 -0
- package/dist/{index-FMf4Unm0.d.cts → index-BfeTR7rO.d.cts} +15 -1
- package/dist/{index-vnyqXaRU.d.ts → index-CODAJePj.d.ts} +15 -1
- package/dist/index-ZoW0HQ_m.d.ts +13 -0
- package/dist/index.cjs +126 -20
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +120 -14
- package/dist/types/index.cjs +2 -2
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +1 -1
- package/package.json +1 -1
- package/src/accounts/actions.ts +3 -3
- package/src/chains/index.ts +1 -0
- package/src/chains/localnet.ts +30 -0
- package/src/client/client.ts +6 -4
- package/src/config/snapID.ts +4 -0
- package/src/contracts/actions.ts +8 -5
- package/src/global.d.ts +1 -1
- package/src/types/clients.ts +7 -0
- package/src/types/index.ts +2 -0
- package/src/types/metamaskClientResult.ts +5 -0
- package/src/types/network.ts +1 -0
- package/src/types/snapSource.ts +1 -0
- package/src/wallet/actions.ts +10 -0
- package/src/wallet/connect.ts +65 -0
- package/src/wallet/metamaskClient.ts +50 -0
- package/tests/client.test-d.ts +2 -2
- package/tests/client.test.ts +7 -7
- package/dist/index-CHQn8ZME.d.cts +0 -10
- package/dist/index-CioK5j0r.d.ts +0 -10
- /package/dist/{chunk-2EJVFGKU.js → chunk-K72OSU5N.js} +0 -0
- /package/dist/{chunk-52HYC24L.cjs → chunk-YDFRDDP5.cjs} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## 0.8.0 (2025-03-12)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* overwrite defaultConsensusMaxRotations ([#75](https://github.com/yeagerai/genlayer-js/issues/75)) ([8d64b42](https://github.com/yeagerai/genlayer-js/commit/8d64b428d8232394cfe1ac5b56edba7c1837d0e5))
|
|
9
|
+
|
|
10
|
+
## 0.7.0 (2025-03-05)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* connect ([#58](https://github.com/yeagerai/genlayer-js/issues/58)) ([7e396c7](https://github.com/yeagerai/genlayer-js/commit/7e396c765536ef0ec1a81c259c113587dc6de8ee))
|
|
16
|
+
|
|
3
17
|
## 0.6.4 (2025-02-04)
|
|
4
18
|
|
|
5
19
|
|
package/README.md
CHANGED
|
@@ -26,11 +26,11 @@ Here’s how to initialize the client and connect to the GenLayer Simulator:
|
|
|
26
26
|
|
|
27
27
|
### Reading a Transaction
|
|
28
28
|
```typescript
|
|
29
|
-
import {
|
|
29
|
+
import { localnet } from 'genlayer-js/chains';
|
|
30
30
|
import { createClient } from "genlayer-js";
|
|
31
31
|
|
|
32
32
|
const client = createClient({
|
|
33
|
-
chain:
|
|
33
|
+
chain: localnet,
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
const transactionHash = "0x...";
|
|
@@ -40,11 +40,11 @@ const transaction = await client.getTransaction({ hash: transactionHash })
|
|
|
40
40
|
|
|
41
41
|
### Reading a contract
|
|
42
42
|
```typescript
|
|
43
|
-
import {
|
|
43
|
+
import { localnet } from 'genlayer-js/chains';
|
|
44
44
|
import { createClient } from "genlayer-js";
|
|
45
45
|
|
|
46
46
|
const client = createClient({
|
|
47
|
-
chain:
|
|
47
|
+
chain: localnet,
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
const result = await client.readContract({
|
|
@@ -58,11 +58,11 @@ const result = await client.readContract({
|
|
|
58
58
|
|
|
59
59
|
### Writing a transaction
|
|
60
60
|
```typescript
|
|
61
|
-
import {
|
|
61
|
+
import { localnet } from 'genlayer-js/chains';
|
|
62
62
|
import { createClient, createAccount } from "genlayer-js";
|
|
63
63
|
|
|
64
64
|
const client = createClient({
|
|
65
|
-
network:
|
|
65
|
+
network: localnet,
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
const account = createAccount();
|
package/dist/chains/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
var _chunkI6HC44KDcjs = require('../chunk-I6HC44KD.cjs');
|
|
4
5
|
require('../chunk-75ZPJI57.cjs');
|
|
5
6
|
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
|
|
9
|
+
exports.localnet = _chunkI6HC44KDcjs.localnet; exports.simulator = _chunkI6HC44KDcjs.simulator;
|
package/dist/chains/index.d.cts
CHANGED
package/dist/chains/index.d.ts
CHANGED
package/dist/chains/index.js
CHANGED
|
@@ -5,15 +5,16 @@ var _chunk75ZPJI57cjs = require('./chunk-75ZPJI57.cjs');
|
|
|
5
5
|
// src/chains/index.ts
|
|
6
6
|
var chains_exports = {};
|
|
7
7
|
_chunk75ZPJI57cjs.__export.call(void 0, chains_exports, {
|
|
8
|
+
localnet: () => localnet,
|
|
8
9
|
simulator: () => simulator
|
|
9
10
|
});
|
|
10
11
|
|
|
11
|
-
// src/chains/
|
|
12
|
+
// src/chains/localnet.ts
|
|
12
13
|
var _viem = require('viem');
|
|
13
14
|
var SIMULATOR_JSON_RPC_URL = "http://127.0.0.1:4000/api";
|
|
14
|
-
var
|
|
15
|
+
var localnet = _viem.defineChain.call(void 0, {
|
|
15
16
|
id: 61999,
|
|
16
|
-
name: "
|
|
17
|
+
name: "Genlayer Localnet",
|
|
17
18
|
rpcUrls: {
|
|
18
19
|
default: {
|
|
19
20
|
http: [SIMULATOR_JSON_RPC_URL]
|
|
@@ -36,7 +37,36 @@ var simulator = _viem.defineChain.call(void 0, {
|
|
|
36
37
|
defaultConsensusMaxRotations: 3
|
|
37
38
|
});
|
|
38
39
|
|
|
40
|
+
// src/chains/simulator.ts
|
|
41
|
+
|
|
42
|
+
var SIMULATOR_JSON_RPC_URL2 = "http://127.0.0.1:4000/api";
|
|
43
|
+
var simulator = _viem.defineChain.call(void 0, {
|
|
44
|
+
id: 61999,
|
|
45
|
+
name: "GenLayer Simulator",
|
|
46
|
+
rpcUrls: {
|
|
47
|
+
default: {
|
|
48
|
+
http: [SIMULATOR_JSON_RPC_URL2]
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
nativeCurrency: {
|
|
52
|
+
name: "GEN Token",
|
|
53
|
+
symbol: "GEN",
|
|
54
|
+
decimals: 18
|
|
55
|
+
},
|
|
56
|
+
blockExplorers: {
|
|
57
|
+
default: {
|
|
58
|
+
name: "GenLayer Explorer",
|
|
59
|
+
url: SIMULATOR_JSON_RPC_URL2
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
testnet: true,
|
|
63
|
+
consensusMainContract: null,
|
|
64
|
+
defaultNumberOfInitialValidators: 5,
|
|
65
|
+
defaultConsensusMaxRotations: 3
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
|
|
39
69
|
|
|
40
70
|
|
|
41
71
|
|
|
42
|
-
exports.simulator = simulator; exports.chains_exports = chains_exports;
|
|
72
|
+
exports.localnet = localnet; exports.simulator = simulator; exports.chains_exports = chains_exports;
|
|
@@ -5,15 +5,16 @@ import {
|
|
|
5
5
|
// src/chains/index.ts
|
|
6
6
|
var chains_exports = {};
|
|
7
7
|
__export(chains_exports, {
|
|
8
|
+
localnet: () => localnet,
|
|
8
9
|
simulator: () => simulator
|
|
9
10
|
});
|
|
10
11
|
|
|
11
|
-
// src/chains/
|
|
12
|
+
// src/chains/localnet.ts
|
|
12
13
|
import { defineChain } from "viem";
|
|
13
14
|
var SIMULATOR_JSON_RPC_URL = "http://127.0.0.1:4000/api";
|
|
14
|
-
var
|
|
15
|
+
var localnet = defineChain({
|
|
15
16
|
id: 61999,
|
|
16
|
-
name: "
|
|
17
|
+
name: "Genlayer Localnet",
|
|
17
18
|
rpcUrls: {
|
|
18
19
|
default: {
|
|
19
20
|
http: [SIMULATOR_JSON_RPC_URL]
|
|
@@ -36,7 +37,36 @@ var simulator = defineChain({
|
|
|
36
37
|
defaultConsensusMaxRotations: 3
|
|
37
38
|
});
|
|
38
39
|
|
|
40
|
+
// src/chains/simulator.ts
|
|
41
|
+
import { defineChain as defineChain2 } from "viem";
|
|
42
|
+
var SIMULATOR_JSON_RPC_URL2 = "http://127.0.0.1:4000/api";
|
|
43
|
+
var simulator = defineChain2({
|
|
44
|
+
id: 61999,
|
|
45
|
+
name: "GenLayer Simulator",
|
|
46
|
+
rpcUrls: {
|
|
47
|
+
default: {
|
|
48
|
+
http: [SIMULATOR_JSON_RPC_URL2]
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
nativeCurrency: {
|
|
52
|
+
name: "GEN Token",
|
|
53
|
+
symbol: "GEN",
|
|
54
|
+
decimals: 18
|
|
55
|
+
},
|
|
56
|
+
blockExplorers: {
|
|
57
|
+
default: {
|
|
58
|
+
name: "GenLayer Explorer",
|
|
59
|
+
url: SIMULATOR_JSON_RPC_URL2
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
testnet: true,
|
|
63
|
+
consensusMainContract: null,
|
|
64
|
+
defaultNumberOfInitialValidators: 5,
|
|
65
|
+
defaultConsensusMaxRotations: 3
|
|
66
|
+
});
|
|
67
|
+
|
|
39
68
|
export {
|
|
69
|
+
localnet,
|
|
40
70
|
simulator,
|
|
41
71
|
chains_exports
|
|
42
72
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { S as SimulatorChain } from './chains-C5PI_Nr_.cjs';
|
|
2
|
+
|
|
3
|
+
declare const localnet: SimulatorChain;
|
|
4
|
+
|
|
5
|
+
declare const simulator: SimulatorChain;
|
|
6
|
+
|
|
7
|
+
declare const index_localnet: typeof localnet;
|
|
8
|
+
declare const index_simulator: typeof simulator;
|
|
9
|
+
declare namespace index {
|
|
10
|
+
export { index_localnet as localnet, index_simulator as simulator };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { index as i, localnet as l, simulator as s };
|
|
@@ -91,6 +91,16 @@ type ContractSchema = {
|
|
|
91
91
|
methods: ContractMethod[];
|
|
92
92
|
};
|
|
93
93
|
|
|
94
|
+
type Network = 'localnet' | 'testnet' | 'mainnet';
|
|
95
|
+
|
|
96
|
+
type SnapSource = 'npm' | 'local';
|
|
97
|
+
|
|
98
|
+
type MetaMaskClientResult = {
|
|
99
|
+
isFlask: boolean;
|
|
100
|
+
installedSnaps: Record<string, any>;
|
|
101
|
+
isGenLayerSnapInstalled: boolean;
|
|
102
|
+
};
|
|
103
|
+
|
|
94
104
|
type GenLayerMethod = {
|
|
95
105
|
method: "sim_fundAccount";
|
|
96
106
|
params: [address: string, amount: number];
|
|
@@ -143,6 +153,7 @@ type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<Client<Transp
|
|
|
143
153
|
};
|
|
144
154
|
value: bigint;
|
|
145
155
|
leaderOnly?: boolean;
|
|
156
|
+
consensusMaxRotations?: number;
|
|
146
157
|
}) => Promise<any>;
|
|
147
158
|
deployContract: (args: {
|
|
148
159
|
account?: Account;
|
|
@@ -152,6 +163,7 @@ type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<Client<Transp
|
|
|
152
163
|
[key: string]: CalldataEncodable;
|
|
153
164
|
};
|
|
154
165
|
leaderOnly?: boolean;
|
|
166
|
+
consensusMaxRotations?: number;
|
|
155
167
|
}) => Promise<`0x${string}`>;
|
|
156
168
|
getTransaction: (args: {
|
|
157
169
|
hash: TransactionHash;
|
|
@@ -168,6 +180,8 @@ type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<Client<Transp
|
|
|
168
180
|
getContractSchema: (address: string) => Promise<ContractSchema>;
|
|
169
181
|
getContractSchemaForCode: (contractCode: string | Uint8Array) => Promise<ContractSchema>;
|
|
170
182
|
initializeConsensusSmartContract: (forceReset?: boolean) => Promise<void>;
|
|
183
|
+
connect: (network?: Network, snapSource?: SnapSource) => Promise<void>;
|
|
184
|
+
metamaskClient: (snapSource?: SnapSource) => Promise<MetaMaskClientResult>;
|
|
171
185
|
};
|
|
172
186
|
|
|
173
|
-
export { type Address as A, type CalldataEncodable as C, type GenLayerClient as G, type MethodDescription as M, type TransactionDataElement$1 as T, CalldataAddress as a, type GenLayerMethod as b, type ContractParamsArraySchemaElement as c, type ContractParamsSchema as d, type ContractMethodBase as e, type ContractMethod as f, type ContractSchema as g, type TransactionHash as h, TransactionStatus as i, type GenLayerTransaction as j, type TransactionDataElement as k };
|
|
187
|
+
export { type Address as A, type CalldataEncodable as C, type GenLayerClient as G, type MethodDescription as M, type Network as N, type SnapSource as S, type TransactionDataElement$1 as T, CalldataAddress as a, type GenLayerMethod as b, type ContractParamsArraySchemaElement as c, type ContractParamsSchema as d, type ContractMethodBase as e, type ContractMethod as f, type ContractSchema as g, type TransactionHash as h, TransactionStatus as i, type GenLayerTransaction as j, type TransactionDataElement as k };
|
|
@@ -91,6 +91,16 @@ type ContractSchema = {
|
|
|
91
91
|
methods: ContractMethod[];
|
|
92
92
|
};
|
|
93
93
|
|
|
94
|
+
type Network = 'localnet' | 'testnet' | 'mainnet';
|
|
95
|
+
|
|
96
|
+
type SnapSource = 'npm' | 'local';
|
|
97
|
+
|
|
98
|
+
type MetaMaskClientResult = {
|
|
99
|
+
isFlask: boolean;
|
|
100
|
+
installedSnaps: Record<string, any>;
|
|
101
|
+
isGenLayerSnapInstalled: boolean;
|
|
102
|
+
};
|
|
103
|
+
|
|
94
104
|
type GenLayerMethod = {
|
|
95
105
|
method: "sim_fundAccount";
|
|
96
106
|
params: [address: string, amount: number];
|
|
@@ -143,6 +153,7 @@ type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<Client<Transp
|
|
|
143
153
|
};
|
|
144
154
|
value: bigint;
|
|
145
155
|
leaderOnly?: boolean;
|
|
156
|
+
consensusMaxRotations?: number;
|
|
146
157
|
}) => Promise<any>;
|
|
147
158
|
deployContract: (args: {
|
|
148
159
|
account?: Account;
|
|
@@ -152,6 +163,7 @@ type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<Client<Transp
|
|
|
152
163
|
[key: string]: CalldataEncodable;
|
|
153
164
|
};
|
|
154
165
|
leaderOnly?: boolean;
|
|
166
|
+
consensusMaxRotations?: number;
|
|
155
167
|
}) => Promise<`0x${string}`>;
|
|
156
168
|
getTransaction: (args: {
|
|
157
169
|
hash: TransactionHash;
|
|
@@ -168,6 +180,8 @@ type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<Client<Transp
|
|
|
168
180
|
getContractSchema: (address: string) => Promise<ContractSchema>;
|
|
169
181
|
getContractSchemaForCode: (contractCode: string | Uint8Array) => Promise<ContractSchema>;
|
|
170
182
|
initializeConsensusSmartContract: (forceReset?: boolean) => Promise<void>;
|
|
183
|
+
connect: (network?: Network, snapSource?: SnapSource) => Promise<void>;
|
|
184
|
+
metamaskClient: (snapSource?: SnapSource) => Promise<MetaMaskClientResult>;
|
|
171
185
|
};
|
|
172
186
|
|
|
173
|
-
export { type Address as A, type CalldataEncodable as C, type GenLayerClient as G, type MethodDescription as M, type TransactionDataElement$1 as T, CalldataAddress as a, type GenLayerMethod as b, type ContractParamsArraySchemaElement as c, type ContractParamsSchema as d, type ContractMethodBase as e, type ContractMethod as f, type ContractSchema as g, type TransactionHash as h, TransactionStatus as i, type GenLayerTransaction as j, type TransactionDataElement as k };
|
|
187
|
+
export { type Address as A, type CalldataEncodable as C, type GenLayerClient as G, type MethodDescription as M, type Network as N, type SnapSource as S, type TransactionDataElement$1 as T, CalldataAddress as a, type GenLayerMethod as b, type ContractParamsArraySchemaElement as c, type ContractParamsSchema as d, type ContractMethodBase as e, type ContractMethod as f, type ContractSchema as g, type TransactionHash as h, TransactionStatus as i, type GenLayerTransaction as j, type TransactionDataElement as k };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { S as SimulatorChain } from './chains-C5PI_Nr_.js';
|
|
2
|
+
|
|
3
|
+
declare const localnet: SimulatorChain;
|
|
4
|
+
|
|
5
|
+
declare const simulator: SimulatorChain;
|
|
6
|
+
|
|
7
|
+
declare const index_localnet: typeof localnet;
|
|
8
|
+
declare const index_simulator: typeof simulator;
|
|
9
|
+
declare namespace index {
|
|
10
|
+
export { index_localnet as localnet, index_simulator as simulator };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { index as i, localnet as l, simulator as s };
|
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var _chunkXAQMWSP4cjs = require('./chunk-XAQMWSP4.cjs');
|
|
5
4
|
|
|
5
|
+
var _chunkI6HC44KDcjs = require('./chunk-I6HC44KD.cjs');
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
var _chunkYDFRDDP5cjs = require('./chunk-YDFRDDP5.cjs');
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
var _chunk75ZPJI57cjs = require('./chunk-75ZPJI57.cjs');
|
|
@@ -16,8 +17,8 @@ var _viem = require('viem');
|
|
|
16
17
|
function accountActions(client) {
|
|
17
18
|
return {
|
|
18
19
|
fundAccount: async ({ address, amount }) => {
|
|
19
|
-
if (_optionalChain([client, 'access', _ => _.chain, 'optionalAccess', _2 => _2.id]) !==
|
|
20
|
-
throw new Error("Client is not connected to the
|
|
20
|
+
if (_optionalChain([client, 'access', _ => _.chain, 'optionalAccess', _2 => _2.id]) !== _chunkI6HC44KDcjs.localnet.id) {
|
|
21
|
+
throw new Error("Client is not connected to the localnet");
|
|
21
22
|
}
|
|
22
23
|
return client.request({
|
|
23
24
|
method: "sim_fundAccount",
|
|
@@ -167,7 +168,7 @@ function encodeImpl(to, data) {
|
|
|
167
168
|
}
|
|
168
169
|
} else if (data instanceof Map) {
|
|
169
170
|
encodeMap(to, data);
|
|
170
|
-
} else if (data instanceof
|
|
171
|
+
} else if (data instanceof _chunkYDFRDDP5cjs.CalldataAddress) {
|
|
171
172
|
to.push(SPECIAL_ADDR);
|
|
172
173
|
for (const c of data.bytes) {
|
|
173
174
|
to.push(c);
|
|
@@ -216,7 +217,7 @@ function decodeImpl(data, index) {
|
|
|
216
217
|
case BigInt(SPECIAL_ADDR): {
|
|
217
218
|
const res = data.slice(index.i, index.i + 20);
|
|
218
219
|
index.i += 20;
|
|
219
|
-
return new (0,
|
|
220
|
+
return new (0, _chunkYDFRDDP5cjs.CalldataAddress)(res);
|
|
220
221
|
}
|
|
221
222
|
}
|
|
222
223
|
const type = Number(cur & 0xffn) & (1 << BITS_IN_TYPE) - 1;
|
|
@@ -328,7 +329,7 @@ function toStringImpl(data, to) {
|
|
|
328
329
|
to.push("]");
|
|
329
330
|
} else if (data instanceof Map) {
|
|
330
331
|
toStringImplMap(data.entries(), to);
|
|
331
|
-
} else if (data instanceof
|
|
332
|
+
} else if (data instanceof _chunkYDFRDDP5cjs.CalldataAddress) {
|
|
332
333
|
to.push("addr#");
|
|
333
334
|
for (const c of data.bytes) {
|
|
334
335
|
to.push(c.toString(16));
|
|
@@ -439,18 +440,18 @@ var overrideContractActions = (client) => {
|
|
|
439
440
|
return decode(resultBinary);
|
|
440
441
|
};
|
|
441
442
|
client.writeContract = async (args) => {
|
|
442
|
-
const { account, address, functionName, args: callArgs, kwargs, value = 0n, leaderOnly = false } = args;
|
|
443
|
+
const { account, address, functionName, args: callArgs, kwargs, value = 0n, leaderOnly = false, consensusMaxRotations = client.chain.defaultConsensusMaxRotations } = args;
|
|
443
444
|
const data = [encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
444
445
|
const serializedData = serialize(data);
|
|
445
|
-
return _sendTransaction(address, serializedData, account || client.account, value);
|
|
446
|
+
return _sendTransaction(address, serializedData, account || client.account, consensusMaxRotations, value);
|
|
446
447
|
};
|
|
447
448
|
client.deployContract = async (args) => {
|
|
448
|
-
const { account, code, args: constructorArgs, kwargs, leaderOnly = false } = args;
|
|
449
|
+
const { account, code, args: constructorArgs, kwargs, leaderOnly = false, consensusMaxRotations = client.chain.defaultConsensusMaxRotations } = args;
|
|
449
450
|
const data = [code, encode(makeCalldataObject(void 0, constructorArgs, kwargs)), leaderOnly];
|
|
450
451
|
const serializedData = serialize(data);
|
|
451
|
-
return _sendTransaction(_viem.zeroAddress, serializedData, account || client.account);
|
|
452
|
+
return _sendTransaction(_viem.zeroAddress, serializedData, account || client.account, consensusMaxRotations);
|
|
452
453
|
};
|
|
453
|
-
const _sendTransaction = async (recipient, data, senderAccount, value) => {
|
|
454
|
+
const _sendTransaction = async (recipient, data, senderAccount, consensusMaxRotations, value) => {
|
|
454
455
|
if (!senderAccount) {
|
|
455
456
|
throw new Error(
|
|
456
457
|
"No account set. Configure the client with an account or pass an account to this function."
|
|
@@ -468,7 +469,7 @@ var overrideContractActions = (client) => {
|
|
|
468
469
|
senderAccount.address,
|
|
469
470
|
recipient,
|
|
470
471
|
client.chain.defaultNumberOfInitialValidators,
|
|
471
|
-
|
|
472
|
+
consensusMaxRotations,
|
|
472
473
|
data
|
|
473
474
|
]
|
|
474
475
|
});
|
|
@@ -541,14 +542,119 @@ var transactionActions = (client) => ({
|
|
|
541
542
|
}
|
|
542
543
|
});
|
|
543
544
|
|
|
545
|
+
// src/config/snapID.ts
|
|
546
|
+
var snapID = {
|
|
547
|
+
local: "local:http://localhost:8081",
|
|
548
|
+
npm: "npm:genlayer-wallet-plugin"
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
// src/wallet/connect.ts
|
|
552
|
+
var networks = {
|
|
553
|
+
localnet: _chunkI6HC44KDcjs.localnet
|
|
554
|
+
};
|
|
555
|
+
var connect = async (client, network = "localnet", snapSource = "npm") => {
|
|
556
|
+
if (!window.ethereum) {
|
|
557
|
+
throw new Error("MetaMask is not installed.");
|
|
558
|
+
}
|
|
559
|
+
if (network === "testnet" || network === "mainnet") {
|
|
560
|
+
throw new Error(`${network} is not available yet. Please use localnet.`);
|
|
561
|
+
}
|
|
562
|
+
const selectedNetwork = networks[network];
|
|
563
|
+
if (!selectedNetwork) {
|
|
564
|
+
throw new Error(`Network configuration for '${network}' is not available.`);
|
|
565
|
+
}
|
|
566
|
+
const chainIdHex = `0x${selectedNetwork.id.toString(16)}`;
|
|
567
|
+
const chainParams = {
|
|
568
|
+
chainId: chainIdHex,
|
|
569
|
+
chainName: selectedNetwork.name,
|
|
570
|
+
rpcUrls: selectedNetwork.rpcUrls.default.http,
|
|
571
|
+
nativeCurrency: selectedNetwork.nativeCurrency,
|
|
572
|
+
blockExplorerUrls: [_optionalChain([selectedNetwork, 'access', _19 => _19.blockExplorers, 'optionalAccess', _20 => _20.default, 'access', _21 => _21.url])]
|
|
573
|
+
};
|
|
574
|
+
const currentChainId = await window.ethereum.request({ method: "eth_chainId" });
|
|
575
|
+
if (currentChainId !== chainIdHex) {
|
|
576
|
+
await window.ethereum.request({
|
|
577
|
+
method: "wallet_addEthereumChain",
|
|
578
|
+
params: [chainParams]
|
|
579
|
+
});
|
|
580
|
+
await window.ethereum.request({
|
|
581
|
+
method: "wallet_switchEthereumChain",
|
|
582
|
+
params: [{ chainId: chainIdHex }]
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
const id = snapSource === "local" ? snapID.local : snapID.npm;
|
|
586
|
+
const installedSnaps = await window.ethereum.request({ method: "wallet_getSnaps" });
|
|
587
|
+
const isGenLayerSnapInstalled = Object.values(installedSnaps).some(
|
|
588
|
+
(snap) => snap.id === id
|
|
589
|
+
);
|
|
590
|
+
if (!isGenLayerSnapInstalled) {
|
|
591
|
+
await window.ethereum.request({
|
|
592
|
+
method: "wallet_requestSnaps",
|
|
593
|
+
params: {
|
|
594
|
+
[id]: {}
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
client.chain = selectedNetwork;
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
// src/wallet/metamaskClient.ts
|
|
602
|
+
var metamaskClient = async (snapSource = "npm") => {
|
|
603
|
+
if (typeof window === "undefined" || !window.ethereum) {
|
|
604
|
+
throw new Error("MetaMask is not installed.");
|
|
605
|
+
}
|
|
606
|
+
const isFlask = async () => {
|
|
607
|
+
try {
|
|
608
|
+
const clientVersion = await _optionalChain([window, 'access', _22 => _22.ethereum, 'optionalAccess', _23 => _23.request, 'call', _24 => _24({
|
|
609
|
+
method: "web3_clientVersion"
|
|
610
|
+
})]);
|
|
611
|
+
return _optionalChain([clientVersion, 'optionalAccess', _25 => _25.includes, 'call', _26 => _26("flask")]);
|
|
612
|
+
} catch (error) {
|
|
613
|
+
console.error("Error detecting Flask:", error);
|
|
614
|
+
return false;
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
const installedSnaps = async () => {
|
|
618
|
+
try {
|
|
619
|
+
return await _optionalChain([window, 'access', _27 => _27.ethereum, 'optionalAccess', _28 => _28.request, 'call', _29 => _29({
|
|
620
|
+
method: "wallet_getSnaps"
|
|
621
|
+
})]);
|
|
622
|
+
} catch (error) {
|
|
623
|
+
console.error("Error getting installed snaps:", error);
|
|
624
|
+
return {};
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
const isGenLayerSnapInstalled = async () => {
|
|
628
|
+
const id = snapSource === "local" ? snapID.local : snapID.npm;
|
|
629
|
+
const snaps = await installedSnaps();
|
|
630
|
+
return Object.values(snaps).some((snap) => snap.id === id);
|
|
631
|
+
};
|
|
632
|
+
const flaskDetected = await isFlask();
|
|
633
|
+
const snapsList = await installedSnaps();
|
|
634
|
+
const genLayerSnapInstalled = await isGenLayerSnapInstalled();
|
|
635
|
+
return {
|
|
636
|
+
isFlask: flaskDetected,
|
|
637
|
+
installedSnaps: snapsList,
|
|
638
|
+
isGenLayerSnapInstalled: genLayerSnapInstalled
|
|
639
|
+
};
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
// src/wallet/actions.ts
|
|
643
|
+
function walletActions(client) {
|
|
644
|
+
return {
|
|
645
|
+
connect: (network, snapSource) => connect(client, network, snapSource),
|
|
646
|
+
metamaskClient: (snapSource = "npm") => metamaskClient(snapSource)
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
|
|
544
650
|
// src/chains/actions.ts
|
|
545
651
|
function chainActions(client) {
|
|
546
652
|
return {
|
|
547
653
|
initializeConsensusSmartContract: async (forceReset = false) => {
|
|
548
|
-
if (_optionalChain([client, 'access',
|
|
654
|
+
if (_optionalChain([client, 'access', _30 => _30.chain, 'optionalAccess', _31 => _31.id]) !== _chunkI6HC44KDcjs.simulator.id) {
|
|
549
655
|
throw new Error("Client is not connected to the simulator");
|
|
550
656
|
}
|
|
551
|
-
if (!forceReset && _optionalChain([client, 'access',
|
|
657
|
+
if (!forceReset && _optionalChain([client, 'access', _32 => _32.chain, 'access', _33 => _33.consensusMainContract, 'optionalAccess', _34 => _34.address]) && _optionalChain([client, 'access', _35 => _35.chain, 'access', _36 => _36.consensusMainContract, 'optionalAccess', _37 => _37.abi])) {
|
|
552
658
|
return;
|
|
553
659
|
}
|
|
554
660
|
const contractsResponse = await fetch(client.chain.rpcUrls.default.http[0], {
|
|
@@ -573,8 +679,8 @@ function chainActions(client) {
|
|
|
573
679
|
}
|
|
574
680
|
|
|
575
681
|
// src/client/client.ts
|
|
576
|
-
var createClient = (config = { chain:
|
|
577
|
-
const chainConfig = config.chain ||
|
|
682
|
+
var createClient = (config = { chain: _chunkI6HC44KDcjs.localnet }) => {
|
|
683
|
+
const chainConfig = config.chain || _chunkI6HC44KDcjs.localnet;
|
|
578
684
|
if (config.endpoint) {
|
|
579
685
|
chainConfig.rpcUrls.default.http = [config.endpoint];
|
|
580
686
|
}
|
|
@@ -583,7 +689,7 @@ var createClient = (config = { chain: _chunkXAQMWSP4cjs.simulator }) => {
|
|
|
583
689
|
async request({ method, params }) {
|
|
584
690
|
if (method.startsWith("eth_") && isAddress) {
|
|
585
691
|
try {
|
|
586
|
-
return await _optionalChain([window, 'access',
|
|
692
|
+
return await _optionalChain([window, 'access', _38 => _38.ethereum, 'optionalAccess', _39 => _39.request, 'call', _40 => _40({ method, params })]);
|
|
587
693
|
} catch (err) {
|
|
588
694
|
console.warn(`Error using window.ethereum for method ${method}:`, err);
|
|
589
695
|
throw err;
|
|
@@ -618,7 +724,7 @@ var createClient = (config = { chain: _chunkXAQMWSP4cjs.simulator }) => {
|
|
|
618
724
|
chain: chainConfig,
|
|
619
725
|
transport: _viem.custom.call(void 0, customTransport),
|
|
620
726
|
...config.account ? { account: config.account } : {}
|
|
621
|
-
}).extend(_viem.publicActions).extend(_viem.walletActions).extend((client) => accountActions(client)).extend((client) => transactionActions(client)).extend((client) => contractActions(client)).extend((client) => chainActions(client));
|
|
727
|
+
}).extend(_viem.publicActions).extend(_viem.walletActions).extend((client) => accountActions(client)).extend((client) => transactionActions(client)).extend((client) => contractActions(client)).extend((client) => chainActions(client)).extend((client) => walletActions(client));
|
|
622
728
|
baseClient.initializeConsensusSmartContract().catch((error) => {
|
|
623
729
|
console.error("Failed to initialize consensus smart contract:", error);
|
|
624
730
|
});
|
|
@@ -648,4 +754,4 @@ var transactions = transactions_exports;
|
|
|
648
754
|
|
|
649
755
|
|
|
650
756
|
|
|
651
|
-
exports.abi = abi_exports; exports.chains =
|
|
757
|
+
exports.abi = abi_exports; exports.chains = _chunkI6HC44KDcjs.chains_exports; exports.createAccount = createAccount; exports.createClient = createClient; exports.generatePrivateKey = generatePrivateKey;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
2
|
import { Account, Address } from 'viem';
|
|
3
3
|
import { S as SimulatorChain } from './chains-C5PI_Nr_.cjs';
|
|
4
|
-
import { G as GenLayerClient, C as CalldataEncodable, T as TransactionDataElement } from './index-
|
|
4
|
+
import { G as GenLayerClient, C as CalldataEncodable, T as TransactionDataElement } from './index-BfeTR7rO.cjs';
|
|
5
5
|
import * as abitype from 'abitype';
|
|
6
6
|
import * as viem__types_experimental_eip7702_types_authorization from 'viem/_types/experimental/eip7702/types/authorization';
|
|
7
7
|
import * as viem_accounts from 'viem/accounts';
|
|
8
|
-
export { i as chains } from './index-
|
|
8
|
+
export { i as chains } from './index-B8E0qiOq.cjs';
|
|
9
9
|
|
|
10
10
|
interface ClientConfig {
|
|
11
11
|
chain?: {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
2
|
import { Account, Address } from 'viem';
|
|
3
3
|
import { S as SimulatorChain } from './chains-C5PI_Nr_.js';
|
|
4
|
-
import { G as GenLayerClient, C as CalldataEncodable, T as TransactionDataElement } from './index-
|
|
4
|
+
import { G as GenLayerClient, C as CalldataEncodable, T as TransactionDataElement } from './index-CODAJePj.js';
|
|
5
5
|
import * as abitype from 'abitype';
|
|
6
6
|
import * as viem__types_experimental_eip7702_types_authorization from 'viem/_types/experimental/eip7702/types/authorization';
|
|
7
7
|
import * as viem_accounts from 'viem/accounts';
|
|
8
|
-
export { i as chains } from './index-
|
|
8
|
+
export { i as chains } from './index-ZoW0HQ_m.js';
|
|
9
9
|
|
|
10
10
|
interface ClientConfig {
|
|
11
11
|
chain?: {
|