Mokhtar Naamani 0c3770d82a api-examples: use createType 4 rokov pred
..
scripts 0c3770d82a api-examples: use createType 4 rokov pred
src 0e3362bf73 api-examples: manually construct type registry when not requiring api 4 rokov pred
README.md 9e28c05cf2 api-examples: linter fixes 4 rokov pred
package.json 7081f0f62b move api-examples to utils/ folder 4 rokov pred
tsconfig.json 16687b62db api-examples: fix path to augment-types 4 rokov pred

README.md

Joystream API Examples

Repo with examples on how to use the @joystream/types package along with @polkadot/api to communicate with a joystream full node.

Examples

yarn
yarn run status

Example code

import { types } from '@joystream/types'
import { ApiPromise, WsProvider } from '@polkadot/api'

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, types })

  await api.isReady

  // 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(`Chain ${chain} using ${nodeName} v${nodeVersion}`)
}

main()

Scripts

You can run scripts that are found in the ./scripts/ folder:

yarn script example