magiziz / encointer-js

javascript npm packages for encointer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Encointer JS

Encointer JavaScript API monorepo

Contains

Installation

yarn add @encointer/node-api @encointer/worker-api

Usage example

import { EncointerWorker } from '@encointer/worker-api';
import { options } from '@encointer/node-api'

import { ApiPromise } from '@polkadot/api';
import { WsProvider } from '@polkadot/rpc-provider';

communityId = '3LjCHdiNbNLKEtwGtBf6qHGZnfKFyjLu9v3uxVgDL35C';

/// In async function
// connect to Encointer node
const api = await ApiPromise.create({
    ...options({
        /// additional types
    }),
    provider: new WsProvider(nodeAddr)
});

// Get first worker endpoint from registry
const workerEndpoint = await api.query.substrateeRegistry.enclaveRegistry(1)

// Create worker
const worker = new EncointerWorker(workerEndpoint, { api });

// Get public data from worker
const total = await worker.getTotalIssuance(communityId);

console.log('Total issuance:', total);

const bob = keyring.addFromUri('//Bob', { name: 'Bob default' });

// Query balance from worker
const balance = worker.getBalance(bob, communityId);

console.log('Bob owns:', balance);

Publish to npm

// will prompt you to select version to increase, e.g. major, minor, patch etc. (Creates git tag!)
lerna version --force-publish

// apply changes from package.json to */build/package.json 
yarn build

// publish all changes from the build directory to npm
lerna publish from-package --contents build

The lerna commands have been added as scripts to the package.json.

WARN When the packages are linked in the js_encointer_service and yarn install is run, it will create a node_modules folder inside the build folder. Do NOT publish this one. However, with the above sequence, this will be fine, as yarn build cleans the build directory first.

About

javascript npm packages for encointer

License:GNU General Public License v3.0


Languages

Language:TypeScript 95.6%Language:JavaScript 4.1%Language:Nix 0.3%