@ocap/sdk

Forge javascript SDK packages all-in-one

Usage no npm install needed!

<script type="module">
  import ocapSdk from 'https://cdn.skypack.dev/@ocap/sdk';
</script>

README

forge-sdk

styled with prettier docs Gitter

Forge Javascript SDK packages all in one

Table of Contents

Install

npm i @ocap/sdk
// OR
yarn add @ocap/sdk

Usage

ES5(commonjs)

Support Node.js

const OcapSDK = require('@ocap/sdk');

// Connect to multi endpoints
OcapSDK.connect('https://test.abtnetwork.io/api', { name: 'test' });
OcapSDK.connect('https://beta.abtnetwork.io/api', { name: 'beta' });

const sender = OcapSDK.Wallet.fromRandom();
const receiver = OcapSDK.Wallet.fromRandom();

// Declare on test chain
await OcapSDK.declare({ moniker: 'sender', wallet: sender }, { conn: 'test' }).then(console.log);
await OcapSDK.declare({ moniker: 'receiver', wallet: receiver }, { conn: 'test' }).then(console.log);

// Get beta chain info
OcapSDK.getChainInfo({ conn: 'beta' }).then(console.log);

// Get local chain info
OcapSDK.getChainInfo({ conn: 'local' }).then(console.log);

// Poke and transfer on test chain
await OcapSDK.transfer({ to: receiver.address, token: 1, wallet: sender }, { conn: 'test' }).then(console.log);

ES6

If you want to support both node.js and browser, please use lite version And the lite version only supports http connections

import OcapSDK from '@ocap/sdk';

OcapSDK.connect('https://test.abtnetwork.io/api', { name: 'test' });

OcapSDK.getChainInfo().then(console.log);
OcapSDK.declare({
  moniker: 'abcd',
  wallet: OcapSDK.Wallet.fromRandom(),
}).then(console.log);

Util

const OcapSDK = require('@ocap/sdk');

const bn = OcapSDK.Util.fromTokenToUnit(10, 16);
console.log(bn);

Wallet

const OcapSDK = require('@ocap/sdk');

const wallet = OcapSDK.Wallet.fromRandom();
console.log(wallet.toJSON());

Message

const OcapSDK = require('@ocap/sdk');

const message = OcapSDK.Message.createMessage('Transaction', {
  from: 'xxx',
  nonce: 1234,
  itx: {},
});
console.log(message);

Packages Included