|
4 роки тому | |
---|---|---|
.. | ||
augment | 4 роки тому | |
augment-codec | 4 роки тому | |
src | 4 роки тому | |
.eslintignore | 4 роки тому | |
.eslintrc.js | 4 роки тому | |
.gitignore | 4 роки тому | |
.npmignore | 4 роки тому | |
.prettierignore | 4 роки тому | |
README.md | 4 роки тому | |
package.json | 4 роки тому | |
tsconfig-augment-codec.json | 4 роки тому | |
tsconfig-augment.json | 4 роки тому | |
tsconfig-base.json | 4 роки тому | |
tsconfig.json | 4 роки тому |
@joystream/types
The types package is required to register the custom Substrate runtime types when working with @polkadot/api
to communicate with a Joystream full node.
Add the package as a dependency in your project.
yarn add @joystream/types
# or
npm install --save @joystream/types
Call registerJoystreamTypes()
before creating a Polkadot API client.
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();
See joystream-api-examples for some additional examples on usage.