@starkware-industries/starkex-clientlib-js v0.0.3
starkex-clientlib-js is a JavaScript wrapper around the StarkEx API
that can be used in both NodeJS and Browser environments.
starkex-clientlib-js is written in ECMAScript6 and strongly typed and transpiled to ECMAScript5 using TypeScript.
Installation
This package is Typescript ready
// using npm
npm i starkex-clientlib-js
// using yarn
yarn add starkex-clientlib-jsHow to use it
The library is a default export.
Browser
To use it browser, you need to use the code from browser.js file.]()
<script src="path-to-local-library/browser.js"></script>or via CDN
<script src="https://path-to-cdn-library/browser.js"></script>In this scenario, the library will be bound to the global window object with the property StarkExAPI.
window.StarkExAPI or simple StarkExAPI can be used to access the library.
If you have a toolchain available you can use an import statement.
import StarkExAPI from 'starkex-clientlib-js/browser';const StarkExAPI = require('starkex-clientlib-js/browser');Because is a default export, here you can import it with what name you want
Node
For NodeJS environment, just replace browser with node
import StarkExAPI from 'starkex-clientlib-js/node';const StarkExAPI = require('starkex-clientlib-js/node');Usage
The object imported is a class that first needs to be instantiated:
new StarkExAPI(config: StarkExClientConfig): StarkExClient;Where config is a configuration object of form:
interface StarkExClientConfig {
endpoint: string;
// optional - relevant only for node environment
certs?: {
cert: string;
key: string;
ca?: string;
};
}Example
const starkExAPI = new StarkExAPI({
endpoint: 'https://gw.playground-v2.starkex.co'
});Example with certs (NodeJS environment)
const starkExAPI = new StarkExAPI({
endpoint: 'https://playground.starkex.co',
certs: {
cert: 'USER_CERT',
key: 'USER_KEY'
}
});The StarkExClient object returned from the constructor exposing the different gateways existing on this API:
public gateway: Gateway
This is the StarkEx Services HTTP gateway version2 for all external trading interactions.
Example for is_alive
const isAlive = await starkExAPI.gateway.isAlive();
console.log(isAlive); // gateway is alive!Example for get_first_unused_tx_id
const txId = await starkExAPI.gateway.getFirstUnusedTxId();
console.log(txId); // 69Example for a DepositRequest
const request = {
amount: 4029557120079369747,
starkKey: "0x7c65c1e82e2e662f728b4fa42485e3a0a5d2f346baa9455e3e70682c2094cac",
tokenId: "0x2dd48fd7a024204f7c1bd874da5e709d4713d60c8a70639eb1167b367a9c378",
vaultId: 1654615998
};
const response = await starkExAPI.gateway.deposit(request);
console.log(response); // {"code": "TRANSACTION_PENDING"}Full API docs for gateway can be found here.
public feederGateway: FeederGateway
This is the StarkEx Services HTTP gateway for feeder interactions. The Feeder is a gateway to the StarkEx system for retrieving transaction batch information by external parties
Example for get_batch_ids
const batchIds = await starkExAPI.feederGateway.getBatchIds();
console.log(batchIds); // [10000, 12345]Full API docs for feederGateway can be found here.
public availabilityGateway: AvailabilityGateway
This is the StarkEx Services HTTP gateway for committee interactions.
Example for get_batch_data
const batchId = 5678;
const batchData = await starkExAPI.availabilityGateway.getBatchData(batchId);
console.log(batchData); // {...}Full API docs for availabilityGateway can be found here.
Note: All results will be exactly the raw response from the API.
API Docs
Click here for full API documentation.