-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.ts
46 lines (39 loc) · 1.08 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Import transport from client, and generated server type
import { build_client, ws } from "@qubit-rs/client";
import type { QubitServer } from "./bindings";
// Polyfill only required for running in NodeJS
import { WebSocket } from "ws";
async function main() {
// Connect with the API
const api = build_client<QubitServer>(
ws(
"ws://localhost:9944/rpc",
// @ts-ignore mis-matching WebSocket definitions
{ WebSocket },
),
);
// Do some maths
for (let i = 0; i < 5; i++) {
await api.increment.mutate();
}
console.log("The value is", await api.get.query());
for (let i = 0; i < 3; i++) {
await api.decrement.mutate();
}
console.log("The value is", await api.get.query());
await api.add.mutate(10);
console.log("The value is", await api.get.query());
console.log("=== Beginning Countdown ===");
await new Promise<void>((resolve) => {
api.countdown.subscribe({
on_data: (n) => {
console.log(`${n}...`);
},
on_end: () => {
resolve();
},
});
});
console.log("=== Lift Off! ===");
}
main();