27 lines
847 B
JavaScript
27 lines
847 B
JavaScript
// Required imports
|
|
const { zip } = require('rxjs');
|
|
const { ApiRx } = require('@plugnet/api');
|
|
const { WsProvider } = require('@plugnet/rpc-provider');
|
|
|
|
function main () {
|
|
// Initialise the provider to connect to the local node
|
|
const provider = new WsProvider('ws://127.0.0.1:9944');
|
|
|
|
// Create the API and wait until ready
|
|
const api = await ApiRx.create(provider).toPromise();
|
|
|
|
// We're using RxJs 'zip()' combination operator to get the emitted values
|
|
// of multiple observables as an array
|
|
zip(
|
|
api.rpc.system.chain(),
|
|
api.rpc.system.name(),
|
|
api.rpc.system.version()
|
|
)
|
|
// Then we subscribe to the result
|
|
.subscribe(([chain, nodeName, nodeVersion]) => {
|
|
console.log(`You are connected to chain ${chain} using ${nodeName} v${nodeVersion}`);
|
|
});
|
|
}
|
|
|
|
main().catch(console.error).finally(() => process.exit());
|