https://github.com/joystream/joystream-api-examples
API examples
https://github.com/joystream/joystream-api-examples
Last synced: about 1 year ago
JSON representation
API examples
- Host: GitHub
- URL: https://github.com/joystream/joystream-api-examples
- Owner: Joystream
- Created: 2019-05-16T23:42:16.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-07-07T05:12:48.000Z (almost 4 years ago)
- Last Synced: 2023-04-10T20:07:24.611Z (about 3 years ago)
- Language: TypeScript
- Size: 201 KB
- Stars: 3
- Watchers: 3
- Forks: 10
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```javascript
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/](./scripts) folder:
```sh
yarn script example
```