genlayer-js 0.27.6 → 0.27.8
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 +45 -0
- package/dist/index.cjs +29 -23
- package/dist/index.js +29 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -168,6 +168,51 @@ 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, create two clients: one for reads (no wallet needed) and one for writes (signed by the wallet). This follows the standard viem pattern and keeps concerns separated.
|
|
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
|
+
// Read client — talks directly to GenLayer RPC, no wallet needed
|
|
181
|
+
const readClient = createClient({
|
|
182
|
+
chain: testnetBradbury,
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// Write client — signs transactions through the wallet
|
|
186
|
+
const writeClient = createClient({
|
|
187
|
+
chain: testnetBradbury,
|
|
188
|
+
account: address as `0x${string}`, // from wallet connection
|
|
189
|
+
provider: window.ethereum, // or from a wallet SDK
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// Use readClient for all reads
|
|
193
|
+
const result = await readClient.readContract({
|
|
194
|
+
address: contractAddress,
|
|
195
|
+
functionName: "get_storage",
|
|
196
|
+
args: [],
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const tx = await readClient.getTransaction({ hash: txHash });
|
|
200
|
+
|
|
201
|
+
// Use writeClient for transactions (MetaMask popup)
|
|
202
|
+
const txHash = await writeClient.writeContract({
|
|
203
|
+
address: contractAddress,
|
|
204
|
+
functionName: "update_storage",
|
|
205
|
+
args: ["new_value"],
|
|
206
|
+
value: BigInt(0),
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// Either client can wait for receipts
|
|
210
|
+
const receipt = await readClient.waitForTransactionReceipt({
|
|
211
|
+
hash: txHash,
|
|
212
|
+
status: TransactionStatus.ACCEPTED,
|
|
213
|
+
});
|
|
214
|
+
```
|
|
215
|
+
|
|
171
216
|
### Staking Operations
|
|
172
217
|
|
|
173
218
|
The SDK provides staking functionality for validators and delegators on testnet-bradbury (and testnet-asimov).
|
package/dist/index.cjs
CHANGED
|
@@ -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 (
|
|
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
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
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
|
@@ -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 (
|
|
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
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
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
|
};
|