# gmd-nodejs-sdk

> SDK to interact with Coop Network GMD node using NodeJS or browser

Latest version **2.0.4** (published 2022-08-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install gmd-nodejs-sdk
pnpm add gmd-nodejs-sdk
yarn add gmd-nodejs-sdk
bun add gmd-nodejs-sdk
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.4 |
| Published | 2022-08-25 |
| First published | 2022-02-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16.10.0 |
| Dependencies | 1 |
| Unpacked size | 106.7 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | George A. |
| Maintainers | zupermann |
| Keywords | CoopNetwork, GMD, SDK |

## Links

- npm: https://www.npmjs.com/package/gmd-nodejs-sdk
- Repository: https://github.com/zupermann/GMD-nodejs-sdk
- Homepage: https://github.com/zupermann/gmd-nodejs-sdk#readme
- Issues: https://github.com/zupermann/gmd-nodejs-sdk/issues
- npm.io page: https://npm.io/package/gmd-nodejs-sdk

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^0.26.0

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 2.0.4 (latest) — 2022-08-25
- 2.0.5-3 (next) — 2022-09-10
- 2.0.5-2 — 2022-09-10
- 2.0.5-1 — 2022-09-10
- 2.0.5-0 — 2022-08-27
- 2.0.4-7 — 2022-08-25
- 2.0.4-6 — 2022-08-25
- 2.0.4-5 — 2022-08-22
- 2.0.4-4 — 2022-08-21
- 2.0.4-3 — 2022-08-21
- 2.0.4-2 — 2022-08-21
- 2.0.4-1 — 2022-08-21
- 2.0.4-0 — 2022-08-21
- 2.0.3 — 2022-08-21
- 1.3.1 — 2022-08-14
- … 9 more at https://npm.io/package/gmd-nodejs-sdk/versions

## README

### Intro 

- This is an SDK to interact with Coop Network Node.
- Main use is for local signing of transactions.
- Offers helper functions to easily call Coop Network node API.
- This SDK was initially designed for NodeJS. For running it in browser please see browser directory
  - please read browser/readme.md and browser/index.html example


### Instructions
- To run tests: 
  ```
  npm install
  npm run test
  ```
- To use in your NodeJS app:
  ```
  npm install gmd-nodejs-sdk
  ```

##### For browser usage please see browser directory readme.md and index.html example.

### Examples on hot to call the GMD node API
- For a complete list of API endpoints and their exact parameters you can see them on any node in a browser at address <GMD node address>/test (e.g. https://node.thecoopnetwork.io/test )
- All examples in this readme.txt can also be found and ran in test directory.

#### Wallet
```
    //generate a random passphrase of 12 words
    let passPhrase = Wallet.generatePassphrase(12);
    
    //generate a wallet from a passphrase
    //please note that wallet does not store the mnemonic passphrase, but only the generated private key and public key. Mnemonic passphrase cannot be recovered by using Wallet.
    let wallet = await Wallet.fromPassphrase(passPhrase);

    //Create encrypted JSON:
    let encryptedJSON = await Wallet.encryptedJSONFromPassPhrase(passPhrase, "password example 123@@!");
    //recover wallet from encrypted json:
    let wallet = await Wallet.fromEncryptedJSON(encryptedJSON, "password example 123@@!"); 
```

### Provider
- Provider is the component that haddles all interaction with a remote GMD node. It extends the RemoteAPICaller class wich enables the calling of the REST API exposed by a node. Full list of REST API endpoints https://node.thecoopnetwork.io/test: 
- Usage example:
```
    const provider = new Provider(new URL('https://node.thecoopnetwork.io:6877'));
    
    const params = { requestType: 'getTransactionsBulk', pageSize: 3, page: 0}
    const data = await provider.apiCall('get', paramsGetTransactions);
    console.log('List of latest 3 transactions: ' + JSON.stringify(data, null, 2));
```
- Getting the blockchain height:
```
    let blockNo = await provider.getBlockNumber();
    console.log('Blockchain height: ' + blockNo);
```

### Transaction 
- Transaction is an abstract class that models all blockcahin transactions performed on the Coop Network blockchain.
- Any transaction has 5 steps:
  1. Create request JSON
  2. Process request JSON to an unsigned transaction (remote API call to a node is necessary)
  3. Sign the unsigned transaction
  4. Broadcast the signed transaction (remote API call to a node is necessary)
  5. [Optional] Transaction is confirmed after the trasaction is written to the blockchain and at leat one block is written on top of the transaction block (remote API call to a node is necessary).
  - The state of the transaction can only go through each step in the specified order as the output of each step is the input for the next step. 
  - Each step can be executed on different device as long as the output of the previous step is somehow transmited out-of-band (e.g. via QR code). This mechanism is usefull when signing happens on a mobile device. - None of the outputs of the described steps contain any secret so exposing a QR is a safe operation.

  - For now, only concrete implementation of Transaction is "SendMoney" class, but further transactions will be added in the future.
  - Example on how to use "SendMoney":
  ```
    provider = new Provider(new URL('https://node.coopnetwork.io:6877'));
    wallet = await Wallet.fromPassphrase('screen drawn leave power connect confidence liquid everytime wall either poet shook');

    transaction = SendMoney.createTransaction('GMD-43MP-76UW-L69N-ALW39', '10000', wallet.publicKey); // Step 1 - local
    await provider.createUnsignedTransaction(transaction); // Step 2 - remote call
    await wallet.signTransaction(transaction); // Step 3 - local call
    await provider.broadcastTransaction(transaction); // Step 4 - remote call

  ```

---
_Source: https://npm.io/package/gmd-nodejs-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
