Mokhtar Naamani f4cb727dec bump types and metadata npm package version | 2 år sedan | |
---|---|---|
.. | ||
scripts | 2 år sedan | |
src | 2 år sedan | |
README.md | 3 år sedan | |
dev-init-storage.sh | 3 år sedan | |
package.json | 2 år sedan | |
tsconfig.json | 4 år sedan |
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/
You can run typescript commands under the src/
folder simply with:
yarn ts-node src/sudo-init-content-lead.ts
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
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