How to install

Table of Contents

SDK

npm

npm install @unique-nft/sdk

Initialization

Node.js

import { Sdk, Options } from '@unique-nft/sdk';
const options: Options = {
    baseUrl: '<REST API URL>'
};
const sdk = new Sdk(options);

In the baseUrl parameter, you must pass one of the paths to the Unique Network

Opal

https://rest.unique.network/opal/v1

Quartz

https://rest.unique.network/quartz/v1

Unique

https://rest.unique.network/unique/v1

Set a signer

To be able to sign extrinsics, you need to install the Accounts package

npm install @unique-nft/accounts

Pass the singer in the parameters when creating the Client object

import { KeyringProvider } from '@unique-nft/accounts/keyring';
import { KeyringOptions } from '@polkadot/keyring/types';
import { Sdk, Options } from "@unique-nft/sdk";

const options: KeyringOptions = {
  type: 'sr25519',
};
const provider = new KeyringProvider(options);
await provider.init();

const signer = provider.addSeed('<seed of account>');

const clientOptions: Options = {
  baseUrl: 'REST API URL',
  signer,
};
const sdk = new Sdk(clientOptions);

Substrate REST

Substrate REST Deployment - Getting Started Guide

Install

Choose install approach: Docker, Source code or Public endpoints

Docker

docker run -p 3000:3000 -e CHAIN_WS_URL=wss://ws-opal.unique.network uniquenetwork/web:latest

See hub.docker.com page

Git

git clone https://github.com/UniqueNetwork/unique-sdk
cd unique-sdk
npm install
npm run build:web
npm start

Public endpoints

You can use public endpoints for access Unique Web:

Opal

https://web-opal.unique.network

Quartz

https://web-quartz.unique.network

Unique

https://web-unique.unique.network/

Environment Variables

Required

Opal

CHAIN_WS_URL=wss://ws-opal.unique.network

Quartz

CHAIN_WS_URL=wss://ws-quartz.unique.network

Unique

CHAIN_WS_URL=wss://ws.unique.network

Optional

Use SIGNER_SEED for sign method
SIGNER_SEED=type mnemonic here
SIGNER_SEED=//Alice
Port (default 3000)
PORT=3000
IPFS Gateway
IPFS_GATEWAY_URL=https://ipfs.unique.network/ipfs/
IPFS upload URL

IPFS_UPLOAD_URL allows you to specify a setting for uploading files via IPFS.

IPFS_UPLOAD_URL=http://192.168.100.183:5001/api/v0
Cache manager

Extrinsics results cache time:

CACHE_TTL=600

To set up the Redis store to cache extrinsics:

REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_DB=0
Prefix

PREFIX allows you to add a global prefix to API. By default, the prefix is empty.

Secondary endpoints

You can also use a secondary connection for substrate, which allows you to use secondary endpoints.

Substrate endpoints

https://web-unique.unique.network/swagger/dot/
https://web-quartz.unique.network/swagger/ksm/

Secondary environment variables

SECONDARY_CHAIN_WS_URL=wss://kusama-rpc.polkadot.io
SECONDARY_CHAIN_NAME=ksm

or

SECONDARY_CHAIN_WS_URL=wss://rpc.polkadot.io
SECONDARY_CHAIN_NAME=ksm

Substrate Client

npm

npm install @unique-nft/sdk

yarn

yarn add @unique-nft/sdk

git

git clone https://github.com/UniqueNetwork/unique-sdk
cd unique-sdk
npm install
npm run build:sdk

Initialize Substrate Client

import { createSigner } from '@unique-nft/sdk/sign';
import { Sdk } from '@unique-nft/sdk';

(async () => {
  const sdk = await Sdk.create({
    chainWsUrl: 'wss://quartz.unique.network',
    signer: await createSigner({
      seed: '//Alice', // Signer seed phrase if you want to sign extrinsics
    }),
  });
})();