@joystream/js
v1.12.0
Published
Joystream JS package provides utilities required to work with Joystream network.
Downloads
317
Readme
@joystream/js
This package is home to the Joystream.js libraries which provide everything required to work with Joystream network.
@joystream/js/utils
Common utilities used by different Joystreamjs packages@joystream/js/content
Interact with content directory module - managing videos, channels, payouts, assets, categories and curator groups
Installation
yarn install @joystream/js
Development
- Run
yarn
to install dependencies - Run
yarn build
to build the package
Content Submodule (@joystream/js/content)
Interact with content directory module - managing payouts, channels, videos, assets, categories and curator groups
Usage
Getting payout record by channel Id
This function gets the payout record from the remote source. It first fetches the payload
header and then uses the offset
of given channel Id from header to fetch the record.
import { channelPayoutProof } from '@joystream/js/content'
const channelId = 1
const payoutRecord = await channelPayoutProof(channelId)
Getting channel payout record from serialized payload file at given byte
import { channelPayoutProofAtByteOffset } from '@joystream/js/content'
import { readBytesFromFile } from '@joystream/js/utils'
const readContext = 'PATH' // 'PATH' | 'URL'
const inputFilePath = './payload'
const byteOffset = 40
const payoutRecord = await channelPayoutProofAtByteOffset(
readBytesFromFile(readContext, inputFilePath), byteOffset
)
Get header from serialized channel payouts payload file
import { serializedPayloadHeader } from '@joystream/js/content'
import { ChannelPayoutsMetadata } from '@joystream/metadata-protobuf'
import { readBytesFromFile } from '@joystream/js/utils'
const readContext = 'PATH' // 'PATH' | 'URL'
const inputFilePath = './payload'
const serializedHeader = await serializedPayloadHeader(
readBytesFromFile(readContext, inputFilePath)
)
// decode header
const header = ChannelPayoutsMetadata.Header.decode(serializedHeader)
console.log(
header.payloadLengthInBytes,
header.headerLengthInBytes,
header.numberOfChannels,
header.channelPayoutByteOffsets
)
Generate merkle root from serialized channel payouts payload
import { generateCommitmentFromPayloadFile } from '@joystream/js/content'
const inputFilePath = './payload'
const readContext = 'PATH' // 'PATH' | 'URL'
const merkleRoot = await generateCommitmentFromPayloadFile(
readBytesFromFile(readContext, inputFilePath)
)
Utils Submodule (@joystream/js/utils)
Common utilities used by different Joystreamjs packages.
Submodule structure:
src/schemas/json/
JSON schemastypings/
Type definitions generated from JSON schemas usingjson-schema-to-typescript
Usage
Read stream of bytes from file
Read a range of bytes from input file provided start
and end
values.
Both start
and end
are inclusive
import { readBytesFromFile } from '@joystream/js/utils'
const readContext = 'PATH' // 'PATH' | 'URL'
const inputFilePath = './payload'
const start = 10
const end = 20
const bytesReader = readBytesFromFile(readContext, inputFilePath)
const bytes = await bytesReader(start, end)