genlayer-js 0.27.7 → 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 +17 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -170,39 +170,44 @@ console.log(trace.genvm_log); // detailed GenVM execution logs
|
|
|
170
170
|
|
|
171
171
|
### Using with a wallet provider (MetaMask)
|
|
172
172
|
|
|
173
|
-
When building a browser dApp,
|
|
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
174
|
|
|
175
175
|
```typescript
|
|
176
176
|
import { createClient } from "genlayer-js";
|
|
177
177
|
import { testnetBradbury } from "genlayer-js/chains";
|
|
178
178
|
import { TransactionStatus } from "genlayer-js/types";
|
|
179
179
|
|
|
180
|
-
//
|
|
181
|
-
const
|
|
182
|
-
|
|
180
|
+
// Read client — talks directly to GenLayer RPC, no wallet needed
|
|
181
|
+
const readClient = createClient({
|
|
182
|
+
chain: testnetBradbury,
|
|
183
|
+
});
|
|
183
184
|
|
|
184
|
-
|
|
185
|
+
// Write client — signs transactions through the wallet
|
|
186
|
+
const writeClient = createClient({
|
|
185
187
|
chain: testnetBradbury,
|
|
186
|
-
account: address as `0x${string}`,
|
|
187
|
-
provider,
|
|
188
|
+
account: address as `0x${string}`, // from wallet connection
|
|
189
|
+
provider: window.ethereum, // or from a wallet SDK
|
|
188
190
|
});
|
|
189
191
|
|
|
190
|
-
//
|
|
191
|
-
const result = await
|
|
192
|
+
// Use readClient for all reads
|
|
193
|
+
const result = await readClient.readContract({
|
|
192
194
|
address: contractAddress,
|
|
193
195
|
functionName: "get_storage",
|
|
194
196
|
args: [],
|
|
195
197
|
});
|
|
196
198
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
+
const tx = await readClient.getTransaction({ hash: txHash });
|
|
200
|
+
|
|
201
|
+
// Use writeClient for transactions (MetaMask popup)
|
|
202
|
+
const txHash = await writeClient.writeContract({
|
|
199
203
|
address: contractAddress,
|
|
200
204
|
functionName: "update_storage",
|
|
201
205
|
args: ["new_value"],
|
|
202
206
|
value: BigInt(0),
|
|
203
207
|
});
|
|
204
208
|
|
|
205
|
-
|
|
209
|
+
// Either client can wait for receipts
|
|
210
|
+
const receipt = await readClient.waitForTransactionReceipt({
|
|
206
211
|
hash: txHash,
|
|
207
212
|
status: TransactionStatus.ACCEPTED,
|
|
208
213
|
});
|