Skip to content

JavaScript Library

Dmitry edited this page Jan 9, 2019 · 3 revisions

NOTE: Documentation will receive updates along with library updates.

Table of contents

Getting started

Adding excaliburjs.js

First you need to add the library to the project:

NPM

npm install excaliburjs

Yarn

yarn add excaliburjs

Importing into a project

Second you need to import the library into the project:

const Excalibur = require("excaliburjs");

After you need to create an excaliburjs object, where you need to specify the provider ID:

let exchange = new Excalibur("ws://localhost:8546");

In addition, the constructor has two optional parameters, information about which you can find here.

List of methods

Class constructor

Create an excaliburjs object:

let exchange = new Excalibur(inProviderID [, isMainnetAddress, isWebsocketProvider]);

Parameters:

  • inProviderID - String: Allows you to specify the address of the provider.
  • isMainnetAddress - Boolean: (optional) Allows you to choose between the mainnet address and the kovan address, true - mainnetAddress | false - kovanAddress, the default address is mainnet.
  • isWebsocketProvider - Boolean: (optional) Allows you to specify the connection method, true - WebsocketProvider | false - HttpProvider, the default connection method is WebsocketProvider.

Getting an account by it's index

exchange.getAccount(accountIndex, callback);

Parameters:

  • accountIndex - Number: Allows you to specify an account index.
  • callback - Function: Callback, return result or error.

Deposit ETH

exchange.makeDeposit(fromWhere, depositAmount, callback);

Parameters:

  • fromWhere - String: Allows you to specify the user address.
  • depositAmount -Number: Allows you to specify the amount of deposit.
  • callback - Function: Callback, return result or error.

Withdraw ETH

exchange.withdrawFunds(fromWhere, withdrawValue, callback);

Parameters:

  • fromWhere - String: Allows you to specify the user address.
  • withdrawValue -Number: Allows you to specify the amount of funds.
  • callback - Function: Callback, return result or error.

Token deposit

exchange.makeDepositToken(fromWhere, spender, token, tokenDepositValue, callback);

Parameters:

  • fromWhere - String: Allows you to specify the user address.
  • token - String: Allows you to specify token address.
  • tokenDepositValue - Number: Allows you to specify the amount of tokens.
  • callback - Function: Callback, return result or error.

Returns:

Returns object which include approve hash and deposit hash.

Withdraw tokens

exchange.withdrawTokens(fromWhere, spender, token, withdrawTokensValue, callback);

Parameters:

  • fromWhere - String: Allows you to specify the user address
  • token - String: Allows you to specify token address.
  • withdrawTokensValue - Number: Allows you to specify the amount of tokens.
  • callback - Function: Callback, return result or error.

Get wallet balance

exchange.getBalance(token, walletAddress, callback);

Parameters:

  • token - String: Allows you to specify token address.
  • walletAddress - String: Allows you to specify user's wallet address.
  • callback - Function: Callback, return result or error.

Set order

exchange.setOrder(fromWhere, getToken, getAmount, giveToken, giveAmount, expires, nonce, callback);

Parameters:

  • fromWhere - String: Allows you to specify the user address.
  • getToken - String: Allows you to specify the address of the token you want to get.
  • getAmount - Number | BN | String: allows you to specify the received amount of token.
  • giveToken - String: Allows you to specify the address of the token you want to give.
  • giveAmount - Number | BN | String: Allows you to specify the amount of token given.
  • expires - Number: Allows you to specify the block number in which the order expires.
  • nonce - Number: The number of transactions made by the sender prior to this one, it is random number.
  • callback - Function: Callback, return result or error.

Tokens exchange

exchange.swapTokens(fromWhere, getToken, getAmount, giveToken, giveAmount, expires, nonce, walletAddress, amountValue, tokenPair, signature, callback);

Parameters:

  • fromWhere - String: Allows you to specify the user address.
  • getToken - String: Allows you to specify the address of the token you want to get.
  • getAmount - Number | BN | String: allows you to specify the received amount of token.
  • giveToken - String: Allows you to specify the address of the token you want to give.
  • giveAmount - Number | BN | String: Allows you to specify the amount of token given.
  • expires - Number: Allows you to specify the block number in which the order expires.
  • nonce - Number: The number of transactions made by the sender prior to this one, it is random number.
  • walletAddress - String: Allows you to specify user's wallet address.
  • amountValue - Number: Allows you to specify the number of tokens to be exchanged.
  • tokenPair - String: Allows you to specify a pair of exchange tokens.
  • signature - String: Allows you to specify signature.
  • callback - Function: Callback, return result or error.

Cancel order

exchange.cancelOrder(fromWhere, getToken, getAmount, giveToken, giveAmount, expires, nonce, tokenPair, signature, callback);

Parameters:

  • fromWhere - String: Allows you to specify the user address.
  • getToken - String: Allows you to specify the address of the token you want to get.
  • getAmount - Number | BN | String: allows you to specify the received amount of token.
  • giveToken - String: Allows you to specify the address of the token you want to give.
  • giveAmount - Number | BN | String: Allows you to specify the amount of token given.
  • expires - Number: Allows you to specify the block number in which the order expires.
  • nonce - Number: The number of transactions made by the sender prior to this one, it is random number.
  • tokenPair - String: Allows you to specify a pair of exchange tokens.
  • signature - String: Allows you to specify signature.
  • callback - Function: Callback, return result or error.

Perform signature verification

exchange.checkSign(hash, signature, callback);
  • hash - String: Allows you to specify a hash.
  • signature - String: Allows you to specify signature.
  • callback - Function: Callback, return result or error.

Get a signature

exchange.getSign(fromWhere, getToken, getAmount, giveToken, giveAmount, expires, nonce, callback);

Parameters:

  • fromWhere - String: Allows you to specify the user address.
  • getToken - String: Allows you to specify the address of the token you want to get.
  • getAmount - Number | BN | String: allows you to specify the received amount of token.
  • giveToken - String: Allows you to specify the address of the token you want to give.
  • giveAmount - Number | BN | String: Allows you to specify the amount of token given.
  • expires - Number: Allows you to specify the block number in which the order expires.
  • nonce - Number: The number of transactions made by the sender prior to this one, it is random number.
  • callback - Function: Callback, return result or error.

Give approve for the tokens amount

exchange.giveApprove(fromWhere, amountValue, callback);

Parameters:

  • fromWhere - String: Allows you to specify the user address.
  • amountValue - Number: Allows you to specify value transferred in Wei.
  • callback - Function: Callback, return result or error.

Transfer from another wallet

exchange.makeTransfer(startPoint, endPoint, amountValue, callback);

Parameters:

  • startPoint - String: Allows you to specify address of the sender.
  • endPoint - String: Allows you to specify address of the receiver.
  • amountValue - Number: Allows you to specify value transferred in Wei.
  • callback - Function: Callback, return result or error.

Event creation order

exchange.orderEvent(callback);

Parameters:

  • callback - Function: Callback, return result or error.

Deposit ETH without MetaMask

exchange.makeDepositLocal(account, privateKey, gasPriceValue, etherValue, getHash);

Parameters:

  • account - Number: Allows you to specify account address.
  • privateKey - String: Allows you to specify private key of account.
  • gasPriceValue - String: Allows you to specify gas price provided by the sender in wei.
  • etherValue - Number: Allows you to specify ether value.
  • getHash - Function: Callback, return hash.

Withdraw funds without MetaMask

exchange.withdrawFundsLocal(account, privateKey, gasPriceValue, tokenValue, etherValue, getHash);

Parameters:

  • account - Number: Allows you to specify account address.
  • privateKey - String: Allows you to specify private key of account.
  • gasPriceValue - String: Allows you to specify gas price provided by the sender in wei.
  • tokenValue - Number: Allows you to specify token value.
  • etherValue - String: Allows you to specify ether value.
  • getHash - Function: Callback, return hash.

Deposit tokens without MetaMask

exchange.makeDepositTokenLocal(token, account, privateKey, gasPriceValue, tokenValue, etherValue, getHash);

Parameters:

  • token - String: Allows you to specify token address.
  • account - Number: Allows you to specify account address.
  • privateKey - String: Allows you to specify private key of account.
  • gasPriceValue - String: Allows you to specify gas price provided by the sender in wei.
  • tokenValue - Number: Allows you to specify token value.
  • etherValue - String: Allows you to specify ether value.
  • getHash - Function: Callback, return hash.

Tokens withdraw without MetaMask

exchange.withdrawTokensLocal(token, account, privateKey, gasPriceValue, tokenValue, etherValue, getHash);

Parameters:

  • token - String: Allows you to specify token address.
  • account - Number: Allows you to specify account address.
  • privateKey - String: Allows you to specify private key of account.
  • gasPriceValue - String: Allows you to specify gas price provided by the sender in wei.
  • tokenValue - Number: Allows you to specify token value.
  • etherValue - String: Allows you to specify ether value.
  • getHash - Function: Callback, return hash.

Tokens exchange without MetaMask

exchange.swapTokensLocal(account, privateKey, gasPriceValue, getToken, getAmount, giveToken, giveAmount, expires, nonce, walletAddress, signature, tokenValue, etherValue,  tokenPair, getHash);

Parameters:

  • account - Number: Allows you to specify account address.
  • privateKey - String: Allows you to specify private key of account.
  • gasPriceValue - String: Allows you to specify gas price provided by the sender in wei.
  • getToken - String: Allows you to specify the address of the token you want to get.
  • getAmount - Number | BN | String: allows you to specify the received amount of token.
  • giveToken - String: Allows you to specify the address of the token you want to give.
  • giveAmount - Number | BN | String: Allows you to specify the amount of token given.
  • expires - Number: Allows you to specify the block number in which the order expires.
  • nonce - Number: The number of transactions made by the sender prior to this one, it is random number.
  • walletAddress - String: Allows you to specify user's wallet address.
  • signature - String: Allows you to specify signature.
  • tokenValue - Number: Allows you to specify token value.
  • etherValue - String: Allows you to specify ether value.
  • tokenPair - String: Allows you to specify a pair of exchange tokens.
  • getHash - Function: Callback, return hash.

Cancel cryptocurrency buy or sell order without MetaMask

exchange.cancelOrderLocal(account, privateKey, gasPriceValue, getToken, getAmount, giveToken, giveAmount, expires, nonce, signature, etherValue, tokenPair, getHash);

Parameters:

  • account - Number: Allows you to specify account address.
  • privateKey - String: Allows you to specify private key of account.
  • gasPriceValue - String: Allows you to specify gas price provided by the sender in wei.
  • getToken - String: Allows you to specify the address of the token you want to get.
  • getAmount - Number | BN | String: allows you to specify the received amount of token.
  • giveToken - String: Allows you to specify the address of the token you want to give.
  • giveAmount - Number | BN | String: Allows you to specify the amount of token given.
  • expires - Number: Allows you to specify the block number in which the order expires.
  • nonce - Number: The number of transactions made by the sender prior to this one, it is random number.
  • signature - String: Allows you to specify signature.
  • etherValue - String: Allows you to specify ether value.
  • tokenPair - String: Allows you to specify a pair of exchange tokens.
  • getHash - Function: Callback, return hash.

Transform from or to wei

exchange.transformWei(transformValue, transformType = 'from', unit = 'ether');

Parameters:

  • transformValue - Number | BN | String: Allows you to specify value for transformation from wei to unit or from unit to wei.
  • transformType - String: (optional) Allows you to specify the type of transformation, accepts either the value 'from' or the value 'to', the default value is 'from'.
  • unit - String: (optional) Allows you to specify the value to transform "transformValue", the default is 'ether', possible units are:
    • noether: ‘0’
    • wei: "1"
    • kwei: "1000"
    • Kwei: "1000"
    • babbage: "1000"
    • femtoether: "1000"
    • mwei: "1000000"
    • Mwei: "1000000"
    • lovelace: "1000000"
    • picoether: "1000000"
    • gwei: "1000000000"
    • Gwei: "1000000000"
    • shannon: "1000000000"
    • nanoether: "1000000000"
    • nano: "1000000000"
    • szabo: "1000000000000"
    • microether: "1000000000000"
    • micro: "1000000000000"
    • finney: "1000000000000000"
    • milliether: "1000000000000000"
    • milli: "1000000000000000"
    • ether: "1000000000000000000"
    • kether: "1000000000000000000000"
    • grand: "1000000000000000000000"
    • mether: "1000000000000000000000000
    • gether: "1000000000000000000000000000"
    • tether: "1000000000000000000000000000000"

For more information, refer to the web3.js documentation in the "web3.utils" section.

Returns:

Returns the string with the transformed value.

Information about version

exchange.version();

Returns:

Displays information about the version used in the console.

Clone this wiki locally
You can’t perform that action at this time.