Skip to content

Commit 3b3dff3

Browse files
committed
feat(04-zkapp-ui-with-react.mdx): client methods section
1 parent 78fdd33 commit 3b3dff3

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

docs/zkapps/tutorials/04-zkapp-ui-with-react.mdx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,48 @@ The web worker client code resides in the `04-zkapp-browser-ui/ui/app/zkappWorke
259259
```
260260
- With `Comlink.wrap`, create a proxy object `remoteApi` that provides typesafe access the worker's API methods.
261261
262+
- Define methods in the ZkappWorkerClient class that call the corresponding method on `remoteApi`, effectively forwarding the calls to the worker.
263+
264+
```ts
265+
async setActiveInstanceToDevnet() {
266+
return this.remoteApi.setActiveInstanceToDevnet();
267+
}
268+
269+
async loadContract() {
270+
return this.remoteApi.loadContract();
271+
}
272+
273+
async compileContract() {
274+
return this.remoteApi.compileContract();
275+
}
276+
277+
async fetchAccount(publicKeyBase58: string) {
278+
return this.remoteApi.fetchAccount(publicKeyBase58);
279+
}
280+
281+
async initZkappInstance(publicKeyBase58: string) {
282+
return this.remoteApi.initZkappInstance(publicKeyBase58);
283+
}
284+
285+
async getNum(): Promise<Field> {
286+
const result = await this.remoteApi.getNum();
287+
return Field.fromJSON(JSON.parse(result as string));
288+
}
289+
290+
async createUpdateTransaction() {
291+
return this.remoteApi.createUpdateTransaction();
292+
}
293+
294+
async proveUpdateTransaction() {
295+
return this.remoteApi.proveUpdateTransaction();
296+
}
297+
298+
async getTransactionJSON() {
299+
return this.remoteApi.getTransactionJSON();
300+
}
301+
```
302+
303+
262304
```ts
263305
// Wrap the worker with Comlink to enable direct method invocation
264306
this.remoteApi = Comlink.wrap(this.worker);

0 commit comments

Comments
 (0)