Download Latest Version v2.4.0 source code.zip (136.3 kB)
Email in envelope

Get an email when there's a new version of ADAMANT JavaScript API library

Home / v2.0.0
Name Modified Size InfoDownloads / Week
Parent folder
README.md 2023-11-01 2.8 kB
v2.0.0 source code.tar.gz 2023-11-01 113.0 kB
v2.0.0 source code.zip 2023-11-01 133.5 kB
Totals: 3 Items   249.3 kB 1

Added

  • TypeScript support

The project was fully rewritten in TypeScript, which means it supports typings now.

See examples directory.

  • More API methods

Added more API methods:

```js // before const block = await api.get('blocks/get', { id });

// after const block = await api.getBlock(id); ```

and post() method:

js await api.post('transactions/process', { transaction });

  • getTransactionId() method

Pass signed transaction with signature to get a transaction id as a string:

js import {getTransactionId} from 'adamant-api' const id = getTransactionId(signedTransaction)

See an example for more information.

Fixed

  • Creating multiple instances

Previously, it was not possible to create multiple instances due to the storage of Logger and "Node Manager" data in the modules.

  • Importing module several times

Fixed a bug where importing adamant-api-jsclient caused issues when it was also imported as a dependency.

Changed

  • API Initialization

Now you will create new instances of adamant-api using keyword new:

```js import { AdamantApi } from 'adamant-api';

const api = new AdamantApi({ nodes: [/ ... /] }); ```

  • Socket Initialization

Replace api.socket.initSocket() with api.initSocket().

Use api.socket.on() instead of .initSocket({ onNewMessage() {} }).

```ts // before api.socket.initSocket({ admAddress: 'U1234..', onNewMessage(transaction) { // ... }, });

// after api.initSocket({ admAddress: 'U1234..' });

api.socket.on((transaction: AnyTransaction) => { // ... }); ```

or specify socket option when initializing API:

```ts // socket.ts import { WebSocketClient, TransactionType } from 'adamant-api';

const socket = new WebSocketClient({ admAddress: 'U1234..' });

socket.on([TransactionType.CHAT_MESSAGE, TransactionType.SEND], (transaction) => { // handle chat messages and transfer tokens transactions });

socket.on(TransactionType.VOTE, (transaction) => { // handle vote for delegate transaction });

export { socket }; ```

```ts // api.ts import { AdamantApi } from 'adamant-api'; import { socket } from './socket';

export const api = new AdamantApi({ socket, nodes: [/ ... /], }); ```

Removeed

  • createTransaction()

Use createSendTransaction, createStateTransaction, createChatTransaction, createDelegateTransaction, createVoteTransaction methods instead.

Source: README.md, updated 2023-11-01