Mokhtar Naamani f4cb727dec bump types and metadata npm package version 2 роки тому
..
scripts 23a386b098 Remove Pioneer 2 роки тому
src b47e5b62e3 CLI, api-scripts: Update after runtime StakingHandler bug fix 2 роки тому
README.md f3a066535a Merge branch 'master' into sumer-new-substrate-update-apps 3 роки тому
dev-init-storage.sh eb74d42c6b Colossus & storage dev-init script 3 роки тому
package.json f4cb727dec bump types and metadata npm package version 2 роки тому
tsconfig.json 3db6be3faa cleanup api-examples workspace, rename to api-scripts 4 роки тому

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.

Some useful utilily commands are also included under src/

Directly Execute src/commands.ts

You can run typescript commands under the src/ folder simply with:

yarn ts-node src/sudo-init-content-lead.ts

Adding code to src/

For example you can add a new file test-command.ts:

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

  // 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()

Then run it with:

yarn ts-node src/test-command.ts

Scripts

Some examples of how to write "scripts" is available under ./scripts/ folder. These are "code-snippets" designed primarly for doing queries or very simple transactions. If you follow the example format you can also copy/paste them into https://testnet.joystream.org/#/js for execution.

yarn script example
yarn script test-transfer