get-class-id-and-name.ts 686 B

123456789101112131415161718192021
  1. import { ApiPromise, WsProvider } from '@polkadot/api'
  2. import { types as joyTypes } from '@joystream/types'
  3. import * as BN from 'bn.js'
  4. async function main() {
  5. // Initialize the api
  6. const provider = new WsProvider('ws://127.0.0.1:9944')
  7. const api = await ApiPromise.create({ provider, types: joyTypes })
  8. const n = await api.query.contentDirectory.nextClassId()
  9. const nextClassId = new BN(n.toJSON() as string).toNumber()
  10. for (let id = 0; id < nextClassId; id++) {
  11. const cls = await api.query.contentDirectory.classById(new BN(id))
  12. const { name } = cls.toJSON() as never
  13. console.log(id, name)
  14. }
  15. }
  16. main()
  17. .then(() => process.exit())
  18. .catch(console.error)