genlayer-js 0.27.5 → 0.27.7

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/README.md CHANGED
@@ -168,6 +168,46 @@ console.log(trace.stderr); // standard error output
168
168
  console.log(trace.genvm_log); // detailed GenVM execution logs
169
169
  ```
170
170
 
171
+ ### Using with a wallet provider (MetaMask)
172
+
173
+ When building a browser dApp, pass the wallet address and EIP-1193 provider. The SDK routes signing operations through the wallet and all reads directly to the GenLayer RPC.
174
+
175
+ ```typescript
176
+ import { createClient } from "genlayer-js";
177
+ import { testnetBradbury } from "genlayer-js/chains";
178
+ import { TransactionStatus } from "genlayer-js/types";
179
+
180
+ // Get address and provider from your wallet connection
181
+ const address = "0x..."; // from wallet
182
+ const provider = window.ethereum; // or from a wallet SDK
183
+
184
+ const client = createClient({
185
+ chain: testnetBradbury,
186
+ account: address as `0x${string}`,
187
+ provider,
188
+ });
189
+
190
+ // Reads go directly to GenLayer RPC — no wallet involved
191
+ const result = await client.readContract({
192
+ address: contractAddress,
193
+ functionName: "get_storage",
194
+ args: [],
195
+ });
196
+
197
+ // Writes are signed by the wallet (MetaMask popup)
198
+ const txHash = await client.writeContract({
199
+ address: contractAddress,
200
+ functionName: "update_storage",
201
+ args: ["new_value"],
202
+ value: BigInt(0),
203
+ });
204
+
205
+ const receipt = await client.waitForTransactionReceipt({
206
+ hash: txHash,
207
+ status: TransactionStatus.ACCEPTED,
208
+ });
209
+ ```
210
+
171
211
  ### Staking Operations
172
212
 
173
213
  The SDK provides staking functionality for validators and delegators on testnet-bradbury (and testnet-asimov).
package/dist/index.cjs CHANGED
@@ -1310,7 +1310,7 @@ var transactionActions = (client, publicClient) => ({
1310
1310
  })
1311
1311
  ]);
1312
1312
  const txData = txDataRaw;
1313
- const [txAllData, roundsData] = allDataRaw;
1313
+ const [txAllData, _roundsData] = allDataRaw;
1314
1314
  const transaction = {
1315
1315
  ...txData,
1316
1316
  txExecutionResult: Number(txAllData.txExecutionResult)
@@ -2107,11 +2107,19 @@ function chainActions(_client) {
2107
2107
  }
2108
2108
 
2109
2109
  // src/client/client.ts
2110
+ var PROVIDER_METHODS = /* @__PURE__ */ new Set([
2111
+ "eth_accounts",
2112
+ "eth_requestAccounts",
2113
+ "eth_sendTransaction",
2114
+ "eth_signTransaction",
2115
+ "personal_sign",
2116
+ "eth_signTypedData_v4"
2117
+ ]);
2110
2118
  var getCustomTransportConfig = (config, chainConfig) => {
2111
2119
  const isAddress = typeof config.account !== "object";
2112
2120
  return {
2113
2121
  async request({ method, params = [] }) {
2114
- if (method.startsWith("eth_") && isAddress) {
2122
+ if (PROVIDER_METHODS.has(method) && isAddress) {
2115
2123
  const provider = config.provider || (typeof window !== "undefined" ? window.ethereum : void 0);
2116
2124
  if (provider) {
2117
2125
  try {
@@ -2122,29 +2130,27 @@ var getCustomTransportConfig = (config, chainConfig) => {
2122
2130
  }
2123
2131
  }
2124
2132
  }
2125
- {
2126
- try {
2127
- const response = await fetch(chainConfig.rpcUrls.default.http[0], {
2128
- method: "POST",
2129
- headers: {
2130
- "Content-Type": "application/json"
2131
- },
2132
- body: JSON.stringify({
2133
- jsonrpc: "2.0",
2134
- id: Date.now(),
2135
- method,
2136
- params
2137
- })
2138
- });
2139
- const data = await response.json();
2140
- if (data.error) {
2141
- throw data.error;
2142
- }
2143
- return data.result;
2144
- } catch (err) {
2145
- console.error(`GenLayer RPC error (${method}):`, err.message || err);
2146
- throw err;
2133
+ try {
2134
+ const response = await fetch(chainConfig.rpcUrls.default.http[0], {
2135
+ method: "POST",
2136
+ headers: {
2137
+ "Content-Type": "application/json"
2138
+ },
2139
+ body: JSON.stringify({
2140
+ jsonrpc: "2.0",
2141
+ id: Date.now(),
2142
+ method,
2143
+ params
2144
+ })
2145
+ });
2146
+ const data = await response.json();
2147
+ if (data.error) {
2148
+ throw data.error;
2147
2149
  }
2150
+ return data.result;
2151
+ } catch (err) {
2152
+ console.error(`GenLayer RPC error (${method}):`, err.message || err);
2153
+ throw err;
2148
2154
  }
2149
2155
  }
2150
2156
  };
package/dist/index.js CHANGED
@@ -1310,7 +1310,7 @@ var transactionActions = (client, publicClient) => ({
1310
1310
  })
1311
1311
  ]);
1312
1312
  const txData = txDataRaw;
1313
- const [txAllData, roundsData] = allDataRaw;
1313
+ const [txAllData, _roundsData] = allDataRaw;
1314
1314
  const transaction = {
1315
1315
  ...txData,
1316
1316
  txExecutionResult: Number(txAllData.txExecutionResult)
@@ -2107,11 +2107,19 @@ function chainActions(_client) {
2107
2107
  }
2108
2108
 
2109
2109
  // src/client/client.ts
2110
+ var PROVIDER_METHODS = /* @__PURE__ */ new Set([
2111
+ "eth_accounts",
2112
+ "eth_requestAccounts",
2113
+ "eth_sendTransaction",
2114
+ "eth_signTransaction",
2115
+ "personal_sign",
2116
+ "eth_signTypedData_v4"
2117
+ ]);
2110
2118
  var getCustomTransportConfig = (config, chainConfig) => {
2111
2119
  const isAddress = typeof config.account !== "object";
2112
2120
  return {
2113
2121
  async request({ method, params = [] }) {
2114
- if (method.startsWith("eth_") && isAddress) {
2122
+ if (PROVIDER_METHODS.has(method) && isAddress) {
2115
2123
  const provider = config.provider || (typeof window !== "undefined" ? window.ethereum : void 0);
2116
2124
  if (provider) {
2117
2125
  try {
@@ -2122,29 +2130,27 @@ var getCustomTransportConfig = (config, chainConfig) => {
2122
2130
  }
2123
2131
  }
2124
2132
  }
2125
- {
2126
- try {
2127
- const response = await fetch(chainConfig.rpcUrls.default.http[0], {
2128
- method: "POST",
2129
- headers: {
2130
- "Content-Type": "application/json"
2131
- },
2132
- body: JSON.stringify({
2133
- jsonrpc: "2.0",
2134
- id: Date.now(),
2135
- method,
2136
- params
2137
- })
2138
- });
2139
- const data = await response.json();
2140
- if (data.error) {
2141
- throw data.error;
2142
- }
2143
- return data.result;
2144
- } catch (err) {
2145
- console.error(`GenLayer RPC error (${method}):`, err.message || err);
2146
- throw err;
2133
+ try {
2134
+ const response = await fetch(chainConfig.rpcUrls.default.http[0], {
2135
+ method: "POST",
2136
+ headers: {
2137
+ "Content-Type": "application/json"
2138
+ },
2139
+ body: JSON.stringify({
2140
+ jsonrpc: "2.0",
2141
+ id: Date.now(),
2142
+ method,
2143
+ params
2144
+ })
2145
+ });
2146
+ const data = await response.json();
2147
+ if (data.error) {
2148
+ throw data.error;
2147
2149
  }
2150
+ return data.result;
2151
+ } catch (err) {
2152
+ console.error(`GenLayer RPC error (${method}):`, err.message || err);
2153
+ throw err;
2148
2154
  }
2149
2155
  }
2150
2156
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "genlayer-js",
3
3
  "type": "module",
4
- "version": "0.27.5",
4
+ "version": "0.27.7",
5
5
  "description": "GenLayer JavaScript SDK",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",