From efe503198c472221f54b871c37bf0fe9ab468573 Mon Sep 17 00:00:00 2001 From: Pavel Murygin Date: Sat, 5 Feb 2022 01:03:32 +0300 Subject: [PATCH] Add additional comments --- src/index.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index e26867f..0996f2b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,18 +1,40 @@ -import { Fluence } from '@fluencelabs/fluence'; +import { Fluence, KeyPair } from '@fluencelabs/fluence'; import { krasnodar } from '@fluencelabs/fluence-network-environment'; import { getRelayTimestamp } from './_aqua/export'; +// a node in Krasnodar network to connect to +// NOTE: please, choose another index for your app :) const relay = krasnodar[3]; +// private key for own peer +// NOTE: please, create a new one with `npx aqua create_keypair` command +const sk = Buffer.from('SVz4T4yW718wt0rziDVOfiv6+WQbS4lvEtJHEieXcAk=', 'base64'); + async function main() { + // Here is where we create our peer and connect to the network await Fluence.start({ + KeyPair: await KeyPair.fromEd25519SK(sk), connectTo: relay, }); + // Fluence.getStatus() returns useful information about peer and it's connection + console.log('own peer id: ', Fluence.getStatus().peerId); + console.log('connected to relay: ', Fluence.getStatus().relayPeerId); + console.log('---\n'); + + // here we call aqua function from typescript const timestamp = await getRelayTimestamp(); console.log(new Date(timestamp)); - await Fluence.stop(); + console.log('\n\npress any key to quit...'); + + process.stdin.setRawMode(true); + process.stdin.resume(); + process.stdin.on('data', async () => { + // Stopping the peer before exiting application \ unit test \ etc is a good practice + await Fluence.stop(); + process.exit(0); + }); } main().catch((err) => console.error(err));