# iexec-server-js-client

> JS client to interact with iExec REST API

Latest version **2.0.3** (published 2018-10-12) · ISC license · 0 weekly downloads

## Install

```sh
npm install iexec-server-js-client
pnpm add iexec-server-js-client
yarn add iexec-server-js-client
bun add iexec-server-js-client
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2018-10-12 |
| First published | 2017-12-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 54.3 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 15 |
| Maintainers | sulliwane |

## Links

- npm: https://www.npmjs.com/package/iexec-server-js-client
- Repository: https://github.com/iExecBlockchainComputing/iexec-server-js-client
- Homepage: https://github.com/iExecBlockchainComputing/iexec-server-js-client#readme
- Issues: https://github.com/iExecBlockchainComputing/iexec-server-js-client/issues
- npm.io page: https://npm.io/package/iexec-server-js-client

## Dependencies (9)

- [qs](https://npm.io/package/qs.md) ^6.5.2
- [uuid](https://npm.io/package/uuid.md) 3.3.2
- [debug](https://npm.io/package/debug.md) 4.1.0
- [dev-null](https://npm.io/package/dev-null.md) ^0.1.1
- [through2](https://npm.io/package/through2.md) ^2.0.3
- [jsontoxml](https://npm.io/package/jsontoxml.md) 1.0.1
- [cross-fetch](https://npm.io/package/cross-fetch.md) 2.2.2
- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.26.0
- [xml2js-es6-promise](https://npm.io/package/xml2js-es6-promise.md) ^1.1.1

## Recent versions

- 2.0.3 (latest) — 2018-10-12
- 2.0.1 (next) — 2018-05-30
- 2.0.2 — 2018-09-26
- 2.0.0 — 2018-05-08
- 1.3.2 — 2018-04-24
- 1.3.1 — 2018-04-18
- 1.3.0 — 2018-04-16
- 1.2.6 — 2018-03-22
- 1.2.4 — 2018-03-21
- 1.2.3 — 2018-03-14
- 1.2.2 — 2018-03-14
- 1.2.0 — 2018-03-02
- 1.1.10 — 2018-02-22
- 1.1.9 — 2018-02-20
- 1.1.8 — 2018-02-20
- … 11 more at https://npm.io/package/iexec-server-js-client/versions

## README

# iexec-server-js-client

[![Build Status](https://drone.iex.ec//api/badges/iExecBlockchainComputing/iexec-server-js-client/status.svg)](https://drone.iex.ec/iExecBlockchainComputing/iexec-server-js-client) [![npm version](https://badge.fury.io/js/iexec-server-js-client.svg)](https://www.npmjs.com/package/iexec-server-js-client) [![license](https://img.shields.io/github/license/iExecBlockchainComputing/iexec-server-js-client.svg)](LICENSE)

JS client lib to interact with iExec server REST API

## Ressources

* The iExec server API doc: https://serverapi.iex.ec
* [The iExec SDK](https://github.com/iExecBlockchainComputing/iexec-sdk)
* The iExec main documentation: https://docs.iex.ec

## Examples

Below are examples showcasing the use of the library in the most common worklow:

### 1. Create iExec client

iExec server URL:

* tesnet (ropsten / rinkeby / kovan): `https://testxw.iex.ec:443`
* mainnet: `https://mainxw.iex.ec:443`

```js
const createIEXECClient = require('iexec-server-js-client');
const iexec = createIEXECClient({ server: 'https://testxw.iex.ec:443' });
```

### 2. Auth

Authenticate before hitting iExec API:

```js
iexec.auth(web3.currentProvider, accountAddress).then(({ jwtoken, cookie }) => {
  console.log(jwtoken); // this is given by auth.iex.ec server
  console.log(cookie); // this is given by iExec server
  // hit iExec server API
  iexec.getAppByName(deployTxHash).then(console.log); // print app description from deploy txHash
  iexec.getWorkByExternalID(submitTxHash).then(console.log); // print work description from submit txHash
});
```

If you already have your JWT token, no need to do full auth (avoid wallet signing):

```js
iexec.getCookieByJWT('my_jwt_token').then(cookie => {
  // hit iExec server API
  iexec.getByUID(workUID).then(console.log); // print work description
});
```

### 3. Submit a work

Call the dapp smart contract "iexecSubmit" method to submit a work (for reference only, not part of this repo library):

```js
const oracleJSON = require('iexec-oracle-contract/build/contracts/IexecOracle.json');
const work = '{"cmdline":"10"}'

const oracleContract = web3.eth
  .contract(oracleJSON.abi)
  .at(oracleJSON.networks[chainID].address);
const callbackPrice = await oracleContract.callbackPrice();

const dappContract = web3.eth
  .contract(dappSubmitABI)
  .at(dappAddress);

// this is the work submit
const txHash = await dappContract.iexecSubmit(work, {
  value: callbackPrice[0].toNumber(),
});
```

### 4. Wait for work result

After submitting a work through Ethereum, use the transaction hash (txHash) to wait for the work result:

```js
iexec
  .waitForWorkResult(oracleContract.getWork, txHash)
  .then(workResultURI => iexec.createDownloadURI(workResultURI))
  .then(console.log); // let user open this URL in the browser to download the work result
```

---
_Source: https://npm.io/package/iexec-server-js-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
