Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
71b5889
Removed dependency on gRPC
tgrospic Sep 12, 2020
383f843
Use `bs58` library for base 58 encoding
tgrospic Sep 8, 2020
39f16da
Add rev-address helpers from rnode-grpc-js
tgrospic Sep 13, 2020
d820e57
Add htm library for inline HTML (template literals) in JS
tgrospic Sep 13, 2020
525a5f8
Add JSDoc types to helper functions
tgrospic Sep 13, 2020
8f580b4
TEMP: warning message for testing site
tgrospic Sep 13, 2020
453b9a7
Fix types in comments
tgrospic Sep 24, 2020
38a346e
Full TypeScript support
tgrospic Sep 26, 2020
e1c6d3a
Switch to `preact`, start with tsx
tgrospic Dec 12, 2020
3185cb0
Switch to rnode-http-js
tgrospic Dec 12, 2020
cc9f73b
Move web files to eroot
tgrospic Dec 12, 2020
6248b6e
Update README, RNode 0.9.25.7
tgrospic Dec 12, 2020
915c49a
Move JSON converter to rnode-http-js
tgrospic Dec 13, 2020
89df1d2
Prepare files for conversion to tsx
tgrospic Dec 13, 2020
1d41071
Convert controls render to JSX
tgrospic Dec 13, 2020
f971505
Update rnode-http-js
tgrospic Dec 13, 2020
4dcedad
Update main net validators info
tgrospic Mar 5, 2021
8af9b63
[TEST] Transfer rho without spaces
tgrospic Mar 9, 2021
7bc8c91
Block non digits in REV amount input
tgrospic Jun 5, 2021
1e6c323
Run node with dev-mode (simplify example with one node only)
tgrospic Jun 5, 2021
202ecb1
Update network info for test net 2
tgrospic Jun 5, 2021
bcd0abb
[WIP] Offline transfer download
tgrospic Jun 5, 2021
95afb99
Update for block-merge test net (faucet urls for test nets)
tgrospic Jun 18, 2021
9bccec9
Update for leaderless block-merge test net
tgrospic Oct 14, 2021
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
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# ---------------------------------------------------------------------------------------------------

# RNODE_IMAGE=rchain/rnode
RNODE_IMAGE=rchain/rnode:v0.9.25.2
RNODE_IMAGE=rchain/rnode:v0.10.2

# My network
# ---------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules
dist/
dist-types/
.cache/
.gen
rnode-grpc-*
70 changes: 17 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,88 +1,62 @@
# RNode JS client examples
# 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
npm install && docker-compose up -d && npm run start:web
npm install && docker-compose up -d && npm start

# Logs from all nodes
# Logs from both nodes
docker-compose logs -f
```
</details>

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).
Web example is published from `gh-pages` branch to this url [https://tgrospic.github.io/rnode-client-js](https://tgrospic.github.io/rnode-client-js).

## Nodejs (gRPC)
**Changes on the web page are only saved in memory so it will be lost after refreshing the page.**

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)
## Wallet example with connection to RNode and 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).
Helper functions are in [@tgrospic/rnode-http-js] which contains the code for communication with Metamask, getting selected ETH address and sending deploys for signing.

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.

[@tgrospic/rnode-http-js]: https://github.com/tgrospic/rnode-http-js

## Install

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

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 +75,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)
18 changes: 2 additions & 16 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,17 @@ services:
--wallets-file /data/genesis/wallets.txt --bonds-file /data/genesis/bonds.txt
--tls-certificate-path /data/node.certificate.pem --tls-key-path /data/node.key.pem
--approve-duration 10seconds --approve-interval 10seconds
--dev-mode
ports:
- $MY_NET_IP:40401:40401
- $MY_NET_IP:40402:40402
- $MY_NET_IP:40403:40403
- $MY_NET_IP:40405:40405
# Ports exposed externally
# Ports used in RNode address (exposed externally)
- $MY_NET_IP:40400:40400
- $MY_NET_IP:40404:40404
volumes:
- ./data:/data

read:
<< : *default-rnode
container_name: read
command: run -b $VALIDATOR_BOOT_ADDRESS --allow-private-addresses --host read --no-upnp
--protocol-port 40410 --discovery-port 40414
--approve-duration 10seconds --approve-interval 10seconds
--fork-choice-check-if-stale-interval 30seconds --fork-choice-stale-threshold 30seconds
ports:
- $MY_NET_IP:40411:40401
- $MY_NET_IP:40413:40403
- $MY_NET_IP:40415:40405
# Ports exposed externally
- $MY_NET_IP:40410:40410
- $MY_NET_IP:40414:40414

networks:
rchain-net:
Binary file removed docs/intellisense-vscode.png
Binary file not shown.
Loading