Introduction

@polymathnetwork/polymesh-sdk

Polymesh version

This release is compatible with Polymesh v3.2.0

Getting Started

Purpose

The Polymesh SDK's main goal is to provide external developers with a set of tools that will allow them to build powerful applications that interact with the Polymesh protocol. It focuses on abstracting away all the complexities of the Polymesh blockchain and expose a simple but complete interface. The result is a feature-rich, user-friendly node.js library.

Before moving on

This document assumes you are already familiar with Security Tokens in general and Polymath as well as Polymesh in particular.

Technical Pre-requisites

In order to use the Polymath SDK, you must install node (version 10) and npm. The library is written in typescript, but can also be used in plain javascript. This document will assume you are using typescript, but the translation to javascript is very simple.

Documentation

Token Studio SDK Walkthrough:
Polymesh SDK API Reference:

How to use

Installation

npm i @polymathnetwork/polymesh-sdk --save
Or, if you're using yarn
yarn add @polymathnetwork/polymesh-sdk

Initializing the client

Before you can start registering Tickers and creating Security Tokens, you have to connect the Polymesh SDK client to a Polymesh node. This is a pretty straightforward process:
1
import { Polymesh } from '@polymathnetwork/polymesh-sdk';
2
3
async function run() {
4
const polyClient = await Polymesh.connect({
5
nodeUrl: 'wss://some-node-url.com',
6
accountSeed: 'YOUWISH',
7
});
8
9
// do stuff with the client
10
}
Copied!
Here is an overview of the parameters passed to the connect function:
  • nodeUrl is a URL that points to a running Polymesh node
  • accountSeed is the seed (akin to a private key) of the account that will be performing transactions
NOTE: if using the SDK on a browser environment (i.e. with the Polymesh wallet browser extension), there is no need to provide the account seed. Instead, you pass a Keyring object that contains the address, and a signer for that address (which you would typically get from the wallet extension)
1
import { Polymesh, Keyring } from '@polymathnetwork/polymesh-sdk';
2
3
async function run() {
4
const keyring = new Keyring();
5
keyring.addFromAddress(accountAddress);
6
const signer = getSignerFromExtension(); // this is not an existing function, how you get this depends on the extension
7
8
const polyClient = await Polymesh.connect({
9
nodeUrl: 'wss://some-node-url.com',
10
keyring,
11
signer,
12
});
13
14
// do stuff with the client
15
}
Copied!
Last modified 3mo ago