Options
All
  • Public
  • Public/Protected
  • All
Menu

Atomex SDK

Atomex SDK

npm version Tests License: MIT

Please read the following documents prior to start building on this SDK:

  1. Overview of the Atomex protocol and roles
  2. Atomex protocol entities and API guide
  3. Atomex integration tutorial

In order to run the interactive tutorial:

  1. Install IJavacript
  2. Make sure all dependencies are installed make install
  3. Run make tutorial

Check out the typedoc reference at sdk.atomex.me

Installation

Latest version is available on NPM:

npm install atomex-sdk

SDK components

The Atomex SDK has mainly 2 components:

  • Atomex REST API wrapper Atomex
  • Various helpers for each supported currency/token (derived from Helpers class)

Currently SDK supports the following currencies/tokens:

  • XTZ (tez) — TezosHelpers
  • ETH (ether) — EthereumHelpers

Usage

Atomex API

Start working with Atomex API by creating an instance of the wrapper class.

const atomex = Atomex.create("testnet")

There are several predefined configs:

  • mainnet — for production use
  • testnet — for testing purposes, on-chain operations tracked in:
    • Ethereum: Goerli
    • Tezos: Carthagenet
  • localhost — for Atomex developers only (debugging purposes)

Public methods

Market data can be queried without authentication.

There is also a helper for estimating order price:

Authentication

Atomex uses simple JWT scheme (without refresh tokens). Client is responsible for tracking the expiration and requesting new tokens.
Read more about the authentication process in the overview.

await atomex.getAuthToken({ 
timeStamp: 1606227074301,
message: 'Signing in ',
publicKey:
'419491b1796b13d756d394ed925c10727bca06e97353c5ca09402a9b6b07abcc',
signature:
'd937f12e7509f9266376a4cc6b51af91ad9f2e2c55ce9b3dfd870fc2e9d604b390a0f15d7ea277f8b6b9dfc1bb2ef2218d5ec4f87ba0399e6f6fb6d31ed09e03',
algorithm: 'Ed25519:Blake2b'
})

The following structure is returned if everything is ok:

{ "id":
"dd03c7c3bc9daf23727d0c5759c72855eb1f36c9376f8a67b17fcd3dc07bfba1",
"token":
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6ImRkMDNjN2MzYmM5ZGFmMjM3MjdkMGM1NzU5YzcyODU1ZWIxZjM2YzkzNzZmOGE2N2IxN2ZjZDNkYzA3YmZiYTEiLCJuYmYiOjE2MDYyMzk5OTQsImV4cCI6MTYwNjMyNjM5NCwiaWF0IjoxNjA2MjM5OTk0fQ.ljwKxcQk5mPbRRzZ9qaZioe7U1_3I7riklGCEj2xXPA",
"expires": 1606326394064
}

Assign the token to the Atomex instance:

atomex.setAuthToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6ImRkMDNjN2MzYmM5ZGFmMjM3MjdkMGM1NzU5YzcyODU1ZWIxZjM2YzkzNzZmOGE2N2IxN2ZjZDNkYzA3YmZiYTEiLCJuYmYiOjE2MDYyMzk5OTQsImV4cCI6MTYwNjMyNjM5NCwiaWF0IjoxNjA2MjM5OTk0fQ.ljwKxcQk5mPbRRzZ9qaZioe7U1_3I7riklGCEj2xXPA")

Private methods

With auth token assigned we can work with orders:

And swaps:

Helpers

For each currency create an according helper class instance:

const tez = await TezosHelpers.create("testnet");

You can also specify custom RPC endpoint:

cosnt eth = await EthereumHelpers.create("testnet", "https://goerli.infura.io/v3/12345");

Helpers classes implement a single interface providing methods for interacting with Atomex contracts:

Encoding/decoding crypto primitives:

Generating data for Atomex.getAuthToken request:

Estimating fees:

Tracking transaction confirmations and validating parameters:

Currency-specific helpers

Contributing

Install dependencies

make install

Run linter and compile the library

make

Run unit tests

make test

In order to update the OpenAPI specification:

make spec-update

Generate TypeDoc

make typedoc

Publish to NPM

Bump version in package.json, commit & push

make release

Generated using TypeDoc