-
Notifications
You must be signed in to change notification settings - Fork 2
JavaScript Library
NOTE: Documentation will receive updates along with library updates.
- Getting Started
-
List of methods
- Class constructor
- Getting an account by it's index
- Deposit ETH
- Withdraw ETH
- Token deposit
- Withdraw tokens
- Get wallet balance
- Set order
- Tokens exchange
- Cancel order
- Perform signature verification
- Get a signature
- Give aprove for the tokens amount
- Transfer from another walet
- Event creation order
- Deposit amount without MetaMask
- Withdraw funds without MetaMask
- Deposit tokens without MetaMask
- Tokens withdraw without MetaMask
- Tokens exchange without MetaMask
- Cancel cryptocurrency buy or sell order without MetaMask
- Transform from or to wei
- Information about version
First you need to add the library to the project:
NPM
npm install excaliburjs
Yarn
yarn add excaliburjs
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.
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.
exchange.getAccount(accountIndex, callback);
Parameters:
- accountIndex - Number: Allows you to specify an account index.
- callback - Function: Callback, return result or error.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
exchange.orderEvent(callback);
Parameters:
- callback - Function: Callback, return result or error.
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.
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.
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.
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.
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.
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.
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.
exchange.version();
Returns:
Displays information about the version used in the console.