Repository navigation
Expand file tree
/
Copy pathquickstart.js
More file actions
64 lines (51 loc) · 2.04 KB
/
Copy pathquickstart.js
File metadata and controls
64 lines (51 loc) · 2.04 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2026 Quantova Inc
// SPDX-License-Identifier: Apache-2.0 OR MIT
const { Client, Network, core, generateSeed } = require('@quantovainc/qcore');
const MAX_FEE_QUON = '2000';
const GATEWAY = process.env.QTV_GATEWAY || 'https://q-test-net-01.quantova.org';
async function settle(client, address, ready) {
for (let i = 0; i < 40; i += 1) {
const account = await client.account(address).catch(() => null);
if (account && ready(account)) return account;
await new Promise((wake) => setTimeout(wake, 1500));
}
return null;
}
async function main() {
const seed = generateSeed();
const phrase = core.mnemonicFromSeed(seed);
console.log('mnemonic words', phrase.filter((byte) => byte === 0x20).length + 1);
phrase.fill(0);
const from = core.address(seed, 0n);
const to = core.address(seed, 1n);
console.log('from', from);
console.log('to ', to);
const client = new Client(GATEWAY, { network: Network.testnet() });
const claim = await fetch(GATEWAY + '/faucet/api/claim', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ address: from, amount: 10 }),
}).catch(() => null);
if (!claim || !claim.ok) {
console.log('the faucet did not dispense, so the account has nothing to spend');
return;
}
console.log('faucet sent 10 TQTOV');
const funded = await settle(client, from, (a) => BigInt(a.balance || 0) > 0n);
if (!funded) {
console.log('the faucet payment has not arrived yet, try again in a moment');
return;
}
console.log('balance', funded.balance);
await client.register(seed, 0, MAX_FEE_QUON);
const ready = await settle(client, from, (a) => a.has_key);
if (!ready) {
console.log('the key registration has not landed yet, try again in a moment');
return;
}
console.log('account registered');
const { signed, outcome } = await client.transfer(seed, 0, to, '1000', MAX_FEE_QUON);
console.log('submitted', signed.tx_id, outcome.verdict);
seed.fill(0);
}
main().catch((err) => { console.error(err.message); process.exit(1); });