Skip to content

ArcBlock/forge-js

Repository files navigation

forge-javascript-sdk

Table of Contents

Introduction

lerna docs Gitter

Last updated at 9/7/2022, 2:26:20 PM

Javascript SDK for forge, which is an awesome framework to write distributed blockchain applications.

Packages

Install

npm i @arcblock/forge-sdk
// OR
yarn add @arcblock/forge-sdk

Usage

ES5(commonjs)

Support Node.js

const ForgeSDK = require('@arcblock/forge-sdk');

// Connect to multi endpoints
ForgeSDK.connect('https://test.abtnetwork.io/api', { name: 'test' });
ForgeSDK.connect('https://zinc.abtnetwork.io/api', { name: 'zinc' });
ForgeSDK.connect('tcp://127.0.0.1:28210', { name: 'local' });

// Declare on test chain
ForgeSDK.sendDeclareTx({
  tx: { itx: { moniker: 'abcd' } },
  wallet: ForgeSDK.Wallet.fromRandom(),
}).then(console.log);

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

// Get local chain info
ForgeSDK.getChainInfo({ conn: 'local' }).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 ForgeSDK from '@arcblock/forge-sdk/lite';

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

ForgeSDK.getChainInfo().then(console.log);

Util

const ForgeSDK = require('@arcblock/forge-sdk');

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

Wallet

const ForgeSDK = require('@arcblock/forge-sdk');

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

Message

const ForgeSDK = require('@arcblock/forge-sdk');

const message = ForgeSDK.Message.createMessage('Transaction', { from: 'abcd' });
console.log(message);

Documentation

https://docs.arcblock.io/forge/sdks/javascript/latest/

Contribution

Checkout CONTRIBUTION.md

Compatibility

Forge javascript sdk works with node.js v8.x or above, checkout Travis for status.

Report a Bug?

Bugs and feature requests please create new issues here

License

Copyright 2018-2019 ArcBlock

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.