bwhm b88c355678 set correct endpoint 3 年 前
..
scripts 0eebf573f2 move api-examples 3 年 前
src b88c355678 set correct endpoint 3 年 前
README.md 0eebf573f2 move api-examples 3 年 前
package.json 0eebf573f2 move api-examples 3 年 前
tsconfig.json 0eebf573f2 move api-examples 3 年 前
yarn.lock 0eebf573f2 move api-examples 3 年 前

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 build
yarn run status

Example code

import { registerJoystreamTypes } 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');

  // Register types before creating the API
  registerJoystreamTypes();

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

main();

Scripts

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

yarn script example