genlayer-js 0.27.6 → 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 +40 -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,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
|
@@ -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
|
};
|