Files
api/docs/examples/promise/01_simple_connect/index.js
T
Jaco Greeff c4ba8ca64d Add ts-check for examples (#705)
* Add ts-check for examples

* Typing cleanups, now shows properly

* Bump

* Cleanup checks

* Bump keyring
2019-02-16 12:25:53 +01:00

24 lines
745 B
JavaScript
Executable File

// @ts-check
// Required imports
const { ApiPromise } = require('@polkadot/api');
const { WsProvider } = require('@polkadot/rpc-provider');
async 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 ApiPromise.create(provider);
// Retrieve the chain & node information information via rpc calls
const [chain, nodeName, nodeVersion] = await Promise.all([
api.rpc.system.chain(),
api.rpc.system.name(),
api.rpc.system.version()
]);
console.log(`You are connected to chain ${chain} using ${nodeName} v${nodeVersion}`);
}
main().catch(console.error).finally(() => process.exit());