Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ node_modules
dist/
.cache/
.gen
rnode-grpc-*
59 changes: 12 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# RNode JS client examples
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

# RNode Web API client examples

See also recording of code walk-thru sessions:
- [2020\-07\-28 RChain Education](https://youtu.be/5JEtt53EacI?t=1043)
- [2020\-08\-25 RChain Education](https://www.youtube.com/watch?v=2EUd2vOiJX8)

## Web (HTTP)

In the browser connection to RNode can be done with **RNode Web API**. It's also possible to use gRPC with the proxy.
In the browser connection to RNode can be done with **RNode Web API**.
Web API has only defined schema in Scala source, for the new info please check [RChain issue 2974](https://github.com/rchain/rchain/issues/2974).

For gRPC connection from nodejs please check [**@tgrospic/rnode-grpc-js**](https://github.com/tgrospic/rnode-grpc-js).

<details>
<summary>Quick info to run Web example with two nodes</summary>
<summary>Quick info to run the example with two nodes</summary>

```sh
# Run nodes and web page example
Expand All @@ -23,17 +25,13 @@ docker-compose logs -f

Web example is published from `gh-pages` branch on this url [https://tgrospic.github.io/rnode-client-js](https://tgrospic.github.io/rnode-client-js).

## Nodejs (gRPC)

This repo contains examples how to use [**@tgrospic/rnode-grpc-js**](https://github.com/tgrospic/rnode-grpc-js) helper library to generate **RNode gRPC API** for **Nodejs**.

## Example of RNode connection to Metamask (with hardware wallet)

RNode has support for Ethereum type of signatures so Metamask can be used for signing deploys e.g. making transfers of REVs. In Web example, button to add selected Metamask account should be visible next to REV import textbox.

Helper functions are in [eth-wrapper.js](src/eth/eth-wrapper.js) which contains the code for communication with Metamask, getting selected ETH address and sending deploys for signing.
In [eth-sign.js](src/eth/eth-sign.js) are functions to verify deploy signature and to extract public key.
This is all that is needed for communication with Metamask and also for connected hardware wallets (Ledger). How to use these functions and send deploys to RNode is in [rnode-web.js](src/rnode-web.js).
This is all that is needed for communication with Metamask and also for connected hardware wallets (Ledger, Trezor). How to use these functions and send deploys to RNode is in [rnode-web.js](src/rnode-web.js).

Changes on the web page are only saved in memory so it will be lost after refreshing the page.
RChain networks available for selection are in [rchain-networks.js](src/rchain-networks.js) file.
Expand All @@ -43,46 +41,23 @@ RChain networks available for selection are in [rchain-networks.js](src/rchain-n
Install project dependencies (in `./node_modules` folder).

```sh
# This is enough for HTTP connection to RNode and to run Web example
npm install
```

### Install (gRPC only)

Generate JS bindings (default in `./rnode-grpc-gen`).

```sh
# Defined as script command in package.json
npm run rnode-generate

# Or call executable script directly from npm bin folder
# - which is in the PATH when npm scripts are executed
node_modules/.bin/rnode-grpc
```

## Run **Web example** ([`src/web`](src/web))
## Run ([`src/web`](src/web))

This will start local Nodejs dev server in watch mode [http://localhost:1234](http://localhost:1234).

Test page contains a list of nodes to select, check balance, send transfers and deploys.

```sh
# Run web example
npm run start:web
```

## Run **Nodejs example** ([`src/nodejs/client.js`](src/nodejs/client.js))

In `src/nodejs/client.js` script is an example of how to connect to RNode from Nodejs.

```sh
# Run nodejs example / sample requests to RChain testnet
npm run start:nodejs
npm start
```

## Run RNode with Docker

In the project is [Docker compose](docker-compose.yml) configuration to run local RChain network.
Private key for the validator is in [.env](.env) file. This key is also set in [data/genesis/wallets.txt](data/genesis/wallets.txt) witj initial REV balance to play with.

```sh
# Starts validator and read-only RNode in daemon mode
Expand All @@ -101,15 +76,5 @@ With [GitHub pages action](.github/workflows/github-pages.yml) any commit to _ma

```sh
# Compile static web site (to ./dist folder)
npm run build:web
npm run build
```

## TypeScript definitions (gRPC API)

`rnode-grpc-js` library also generates a TypeScript definition file that can be referenced in your code and can provide IntelliSense support in VSCode.

```typescript
/// <reference path="../../rnode-grpc-gen/js/rnode-grpc-js.d.ts" />
```

![](docs/intellisense-vscode.png)
Binary file removed docs/intellisense-vscode.png
Binary file not shown.
Loading