# gex-client-js

<p>
    <a href=""><img src="https://img.shields.io/npm/v/@galacticexchange/gex-client-js.svg" alt="last commit" height="22"></a>
    <a href=""><img src="https://img.shields.io/github/last-commit/GalacticExchange/gex-client-js.svg" alt="last commit" height="22"></a>
    <a href=""><img src="https://img.shields.io/npm/dt/@galacticexchange/gex-client-js.svg" alt="last commit" height="22"></a>
    <a href=""><img src="https://img.shields.io/npm/l/@galacticexchange/gex-client-js.svg" alt="last commit" height="22"></a>
    
</p>

Galactic Exchange client tools.  
You can use this library to develop browser and Node.js applications that use Galactic Exchange.

!!! warning  
    Library is still at a very early stage, so API may change significantly between minor releases (like 0.2 -> 0.3)

!!! info  
    API for early versions (0.1 - 0.1.27) could be found in GitHub README 

## Getting Started

### Installation 

#### NPM

```bash
npm install @galacticexchange/gex-client-js
```

#### Yarn

```bash
yarn add @galacticexchange/gex-client-js
```

## Initialization

The package includes both non-minified version and a minified version.
For web browsers you will typycally use non-minified version for development and minified version for production mode.  
For Node.js projects you will need to use non-minified version.

#### Require library (minified)

```javascript
const gex = require('@galacticexchange/gex-client-js');
```

#### Require library (non-minified)

```javascript
const gex = require('@galacticexchange/gex-client-js/src/index');
```

#### Init library 


### Init with web socket 

Find out the IP addess and port of the Ethereum blockchain node that you want to connect to.  
Note that the standard port is `8546`. Use the address and the port to init the library as illustrated in the example below.

Note: your blockchain node needs to have WebSockets enabled.  

```javascript
let ip = '51.0.1.99';
let port = '8546';
gex.init(ip, port);
```

### Init with web3Provider

If you wanna use custom web3 provider (like Metamask)

```javascript
gex.initWithProvider(web3Provider);
```


### Init with 2 providers (node + custom)

!!! warning  
    This is temporary solution to use Metamask & receive blockchain events at the same time. See `API Specification -> Events` for more details.

```javascript
let ip = '51.0.1.99';
let port = '8546';
gex.initBothProviders(ip, port, web3Provider);
```
