Prepare the environment by following the instructions in docs/basic_requirements
Clone the project. Then run the following from the Enveloping project's root directory
yarn install && yarn prepare
.- Move here (optional: it runs an RSK node)
We use truffle
for deploying contracts.
npx truffle migrate --network rsk
(disclaimer: rsk network is for Regtest network).
In order to run an instance of Enveloping in Regtest:
- From the jsrelay directory
npx webpack
- From the root directory run
node dist/src/cli/commands/enveloping.js boot-test --network http://localhost:4444/
. (With localhost:4444 a port to an RSK regtest node). - TO check if it is working, run
curl http://localhost:8090/getaddr
We use truffle
for deploying contracts.
npx truffle migrate --network rsktestnet
(disclaimer: to use testnet, you should have an unlocked account with funds or configure it in truffle.js
).
We have already deployed these contracts on Testnet. See here
Each relayed transaction is signed by a Relay Worker account. The worker accounts are controlled by the Relay Manager. When a relay worker signs and relays a transaction, the cost for that transaction is paid using the funds in that worker's account. If the transaction is not subsidized, then the worker is compensated with tokens. Worker accounts must always have some minimum balance to pay gas for the transaction. These balances can be managed by implementing a replenishment strategy. The Relay Manager can use the strategy to top off a relay worker's account when the balance gets too low. We provide a default implementation for a replenishment strategy. Enveloping solution integrators can implement their own replenish strategy.
To implement and use your own replenish strategy:
- In the folder
src/relayserver
, openReplenishFunction.ts
with a text editor. - On the function
replenishStrategy
write your replenish strategy on the then branch. - Re build the project
yarn && yarn prepare
- Add the command
--customReplenish
when running a Relay Server.
In order to run an Enveloping instance in Testnet, clone the project then run the following from the project's root directory:
- Create the project home folder, in this folder the jsrelay databases will be placed:
mkdir enveloping_relay
- In a terminal run
node dist/src/cli/commands/enveloping.js relayer-run --rskNodeUrl "http://localhost:4444" --relayHubAddress=<RELAY_HUB_CONTRACT_ADDRESS> --deployVerifierAddress=<DEPLOY_VERIFIER_CONTRACT_ADDRESS> --relayVerifierAddress=<RELAY_VERIFIER_CONTRACT_ADDRESS> --versionRegistryAddress=<VERSION_REGISTRY_CONTRACT_ADDRESS> --url <RELAY_URL> --port 8090 --workdir enveloping_relay --checkInterval 30000
where<RELAY_HUB_CONTRACT_ADDRESS>
is the address for the relayHub you are using in the current network (see Testnet Contracts section),<RELAY_URL>
in most cases will behttp://localhost
, and the server will be reachable in<RELAY_URL>:port
unless<RELAY_URL>
already defines a port (e.g, if<RELAY_URL>
ishttp://localhost:8090/jsrelay
) - In another terminal run
curl http://localhost:8090/getaddr
which will return some JSON with information of the running jsRelay Server, for example:
{"relayWorkerAddress":"0xe722143177fe9c7c58057dc3d98d87f6c414dc95","relayManagerAddress":"0xe0820002dfaa69cbf8add6a738171e8eb0a5ee54",
"relayHubAddress":"0x38bebd507aBC3D76B10d61f5C95668e1240D087F", "minGasPrice":"6000000000", "chainId":"31", "networkId":"31","ready":false,"version":"2.0.1"}
- Send to relayManagerAddress at least 0.001 tRBTC to set it up
- Send to relayWorkerAddress at least 0.001 tRBTC to set it up
- Once both addresses have been funded, run
node dist/src/cli/commands/enveloping.js relayer-register --network <RSKJ_NODE_URL> --hub <RELAY_HUB_CONTRACT_ADDRESS> -m secret_mnemonic --from <ADDRESS> --funds <FUNDS> --stake <STAKE> --relayUrl <RELAY_URL>
wheresecret_mnemonic
contains the path to a file with the mnemonic of the account to use during the relay server registration,<ADDRESS>
is the account address associated to that mnemonic - Wait until the relay server prints a message saying
RELAY: READY
.
The relay server running in the background. Run the bash file scripts/kill-relay-server.sh