example.js 994 B

1234567891011121314151617181920212223242526272829303132
  1. /* global api, hashing, keyring, types, util, joy */
  2. // run this script with:
  3. // yarn workspace api-scripts script example
  4. //
  5. // or copy and paste the code into the pioneer javascript toolbox at:
  6. // https://testnet.joystream.org/#/js
  7. //
  8. // Example works on nicaea release+
  9. const script = async ({ api, hashing, keyring, types, util, joy }) => {
  10. // Retrieve the chain & node information information via rpc calls
  11. const [chain, nodeName, nodeVersion, runtimeVersion] = await Promise.all([
  12. api.rpc.system.chain(),
  13. api.rpc.system.name(),
  14. api.rpc.system.version(),
  15. api.runtimeVersion,
  16. ])
  17. console.log(`Chain: ${chain}`)
  18. console.log(`Software: ${nodeName} v${nodeVersion}`)
  19. console.log(`Runtime specVersion: ${runtimeVersion.specVersion}`)
  20. }
  21. if (typeof module === 'undefined') {
  22. // Pioneer js-toolbox
  23. // Available globals [api, hashing, keyring, types, util, joy]
  24. script({ api, hashing, keyring, types, util, joy })
  25. } else {
  26. // Node
  27. module.exports = script
  28. }