This typescript repository contains all the server code used by the RIF Relay System.
This project works as a dependency as well as a stand-alone project.
- Node version 12.18
- RSKj Running Node.
- Note: RSKj must run with
miner.minGasPrice=1
(or higher than 0) in regtest to work properly with this server.
- Note: RSKj must run with
- RIF Relay Contracts deployed
To start working with this project you need to first enable postinstall
scripts (refer to section Enabling postinstall scripts).
Then just run npm install
to install all dependencies.
You can use this repository directly to start your server.
To start the relay server, you need to configure the json config file located at <PROJECT_ROOT>/jsrelay/config/relay-config.json
which has this structure:
{
"url": "localhost",
"port": 8090,
"relayHubAddress": "0x3bA95e1cccd397b5124BcdCC5bf0952114E6A701",
"relayVerifierAddress": "0x74Dc4471FA8C8fBE09c7a0C400a0852b0A9d04b2",
"deployVerifierAddress": "0x1938517B0762103d52590Ca21d459968c25c9E67",
"gasPriceFactor": 1,
"rskNodeUrl": "http://rsk-node:4444",
"devMode": true,
"customReplenish": false,
"logLevel": 1,
"workdir": "/home/user/workspace/relay"
}
Where:
- url: is the URL where the relay server will be deployed, it could be localhost or the IP of the host machine.
- port: the port where the relay server will be hosted.
- relayHubAddress: is the relay hub contract address, you can retrieve this from the contract summary.
- relayVerifierAddress: is the relay verifier contract address, you can retrieve this from the contract summary.
- deployVerifierAddress: is the deploy verifier contract address, you can retrieve this from the contract summary.
- gasPriceFactor: is the gas price factor used to calculate the gas on the server, you can leave it as 1.
- rskNodeUrl: is the RSK node endpoint URL, where the RSK node is located.
- devMode: it indicates to the server if we are in development mode or not.
- customReplenish: set if the server uses a custom replenish function or not.
- logLevel: is the log level for the relay server.
- workdir: is the absolute path to the folder where the server will store the database and all its data.
Afterwards, run npm start
to start the server.
You can browse the getAddr
endpoint (e.g. by doing curl
to http://localhost:8090/getaddr
) to verify the server is running correctly as well as visualize some useful information:
{
"relayWorkerAddress": "0xe722143177fe9c7c58057dc3d98d87f6c414dc95",
"relayManagerAddress": "0xe0820002dfaa69cbf8add6a738171e8eb0a5ee54",
"relayHubAddress": "0x38bebd507aBC3D76B10d61f5C95668e1240D087F",
"minGasPrice": "6000000000",
"chainId": "31",
"networkId": "31",
"ready": false,
"version": "2.0.1"
}
If it's the first time the server is run, some logs will state that the server isn't ready and that some values are wrong. This is expected, you just need to register the server on the relay hub in order for it to be usable by the clients.
Once the relay server is up, you need to register it in order for it to be usable.
Run the following command:
npm run register -- -f "<FUNDS>" -s "<STAKE>" -a "<ACCOUNT>" -m "<MNEMONIC>"
The long options command is also available on Linux:
npm run register -- --funds="<FUNDS>" --stake="<STAKE>" --account="<ACCOUNT>" --mnemonic="<MNEMONIC>"
where:
- FUNDS: an optional amount of funds to set up (by default 10)
- STAKE: an optional the amount of stake to set up (by default 20)
- ACCOUNT: an optional account to use for funding and staking (it requires the mnemonic parameter)
- MNEMONIC: an optional mnemonic to use for unlocking the account parameter (it requires the account parameter)
The command shows its usage with the -h
parameter:
npm run register -- -h
After this you will be seeing several log entries indicating how everything is turning out. After a little while, look for this entry in the relay server execution terminal to make sure that the server is ready:
Relayer state: READY
You can use this dependency once you have it installed on your project. There are multiple ways to do this:
Install with:
npm i --save @rsksmart/rif-relay-server
Modify your package.json
file to add the following line:
"@rsksmart/rif-relay-server": "https://github.com/infuy/rif-relay-server",
Clone this repository inside your project's root folder, and modify your package.json
file to add the following line:
"@rsksmart/rif-relay-server": "../rif-relay-server",
If you need to modify resources inside this repository:
- make sure that
postinstall
scripts are enabled in thepackage.json
file. These are disabled by default due to distribution issues (which will be solved in the future), but will enable husky and other tools. - run
npm install
to execute the post install hooks.
After that, make your modifications and then run npm run build
to validate them.
After you are done with your changes you can publish them by creating a distributable version.
To enable postinstall
scripts you need to modify the package.json
file, specifically the scripts
section and change this line:
"_postinstall": "scripts/postinstall",
to
"postinstall": "scripts/postinstall",
We use husky to check linters and code styles on commits, if you commit your changes and the commit fails on lint or prettier checks you can use these command to check and fix the errors before trying to commit again:
npm run lint
: to check linter bugsnpm run lint:fix
: to fix linter bugsnpm run prettier
: to check codestyles errorsnpm run prettier:fix
: to fix codestyles errors
IMPORTANT: when you publish a version postinstall scripts must be disabled. This is disabled by default, so don't push any changes to the postinstall scripts section in the package.json
file.
- Run the
npm run dist
command to generate thedist
folder with the distributable version inside. - Bump the version on the
package.json
file (not strictly needed). - Commit and push any changes, including the version bump.
- Run
npm pack
to generate the tarball to be published as a release on GitHub. - Generate a new release on GitHub and upload the generated tarball.
- Run
npm login
to login to your account on npm registry. - Run
npm publish
to generate the distributable version for NodeJS.
No extra steps are needed beyond generating the dist
folder and merging it to master
.