franciscotobar
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- layout: rsk title: RIF Relay Deployment description: RIF Relay deployment process tags: rif, envelope, relay, user, guide, deployment render_features: 'collapsible tables-with-borders' permalink: /guides/rif-relay/deployment/ --- [](#top "collapsible") - Regtest * Below are the steps to start using RIF Relay locally. All the components will be interacting with the RSKj node that was configured to use Regtest. The executed scripts used the **account[0]** from the local node. [](#top "collapsible") - 1) Contracts Deployment * We will begin by deploying the on-chain components. All the necessary tools to do the deployments were included in [RIF Relay Contract](https://github.com/rsksmart/rif-relay-contracts). To start the process just execute the following command: ``` npx truffle migrate --network regtest ``` > Note: The migrate command is using the Regtest configuration that was previously configured in the truffle.js file. After the deployment we will see the summary of the deployed contracts. Most of this contracts are the on-chain components that will be used by RIF Relay and some are for testing purposes. ``` |===================================|============================================| | Contract | Address | |===================================|============================================| | Penalizer | 0x83C5541A6c8D2dBAD642f385d8d06Ca9B6C731ee | | RelayHub | 0xE0825f57Dd05Ef62FF731c27222A86E104CC4Cad | | Smart Wallet Contracts ========================================================| | SmartWallet | 0x73ec81da0C72DD112e06c09A6ec03B5544d26F05 | | SmartWalletFactory | 0x03F23ae1917722d5A27a2Ea0Bcc98725a2a2a49a | | SmartWalletDeployVerifier | 0x1eD614cd3443EFd9c70F04b6d777aed947A4b0c4 | | SmartWalletRelayVerifier | 0x5159345aaB821172e795d56274D0f5FDFdC6aBD9 | | Custom Smart Wallet Contracts =================================================| | CustomSmartWallet | 0x7557fcE0BbFAe81a9508FF469D481f2c72a8B5f3 | | CustomSmartWalletFactory | 0x0e19674ebc2c2B6Df3e7a1417c49b50235c61924 | | CustomSmartWalletDeployVerifier | 0x8901a2Bbf639bFD21A97004BA4D7aE2BD00B8DA8 | | CustomSmartWalletRelayVerifier | 0x1Af2844A588759D0DE58abD568ADD96BB8B3B6D8 | | Testing Contracts =============================================================| | SampleRecipient | 0xCd5805d60Bbf9Afe69a394c2BDa10F6Dae2c39AF | | TestToken | 0x726ECC75d5D51356AA4d0a5B648790cC345985ED | |===================================|============================================| ``` As we can see we have two sets of Smart Wallets with their own verifiers. This is because each verifier use the factory to do deploy and relay validations. For testing purposes we will be using the Smart Wallet Contracts. - 2) Collector Contract * In principle, any number of Collector contracts can be deployed and used. This does not automatically occur alongside the deployment of the rest of the Relay contracts during the execution of migrations since usage of the Revenue Sharing feature is optional. For an overview of the Collector contract please see [the corresponding architecture document section](/rif/relay/architecture/#collector). Before deploying a Collector contract please make sure that: 1. The token chosen for this contract matches the one used for relayed transaction fees. **Any tokens other than the one set at the time of the Collector deployment which are sent to the contract will be impossible to retrieve, including the native token**. 2. The owner of the Collector contract has been chosen (be it a multisig contract address, a regular contract address or an EOA). This does not need to match the address deploying the contract, but please note that if there are no means of signing Collector contract function calls with the owner address **all revenue sharing funds will be permanently locked in the contract**. 3. Partners and their shares have been defined correctly. This means that beneficiary shares must collectively add up to 100. As with the previous point, any tokens sent to an address without its private key held by its beneficiary will be lost. For an example of a structurally valid revenue shares definition see [this deploy collector task input sample](https://github.com/rsksmart/rif-relay-contracts/blob/PP-94/revenue-sharing-model/deploy-collector.input.sample.json). * To deploy the Collector contract we will be using the [RIF Relay Contract](https://github.com/rsksmart/rif-relay-contracts) and [Safe contracts v1.2.0](https://github.com/gnosis/safe-contracts/tree/v1.2.0). In the safe contracts project we will deploy the contracts in the Regtest network. ``` yarn truffle deploy --network regtest ``` > Take in consideration that the Regtest network needs to be added in the truffle.js file. After the deployment from the safe contracts, we need to switch back to the RIF Relay Contracts repository. In this repository there are some scripts that we will need to execute. Prior executing the scripts we need to update the tasks/utils.js with the contract addresses from the safe contracts deployment: | Name | Mapped | | ----------------------- | ---------------------- | | safeMasterCopyAddress | GnosisSafe | | safeProxyFactoryAddress | GnosisSafeProxyFactory | | multiSendAddress | MultiSend | Now we need to execute the following command, to deploy the multisig contract: ``` npx truffle --network regtest exec tasks/create-safe.js --owners="0x7986b3DF570230288501EEa3D890bd66948C9B79,0x0a3aA774752ec2042c46548456c094A76C7F3a79,0xCF7CDBbB5F7BA79d3ffe74A0bBA13FC0295F6036,0x39B12C05E8503356E3a7DF0B7B33efA4c054C409" ``` > All this accounts are the first 4 accounts from the regtest blockchain that are provided by default. The last step is to deploy the collector contract. To do that we need to create a configuration file with the following structure and save it as deploy-collector.input.json: ```json { "collectorOwner": "0xfC6B663863722F563a9a3234E15493d2b7c365E8", "partners": [ { "beneficiary": "0x7986b3DF570230288501EEa3D890bd66948C9B79", "share": 20 }, { "beneficiary": "0x0a3aA774752ec2042c46548456c094A76C7F3a79", "share": 35 }, { "beneficiary": "0xCF7CDBbB5F7BA79d3ffe74A0bBA13FC0295F6036", "share": 13 }, { "beneficiary": "0x39B12C05E8503356E3a7DF0B7B33efA4c054C409", "share": 32 } ], "tokenAddress": "0x726ECC75d5D51356AA4d0a5B648790cC345985ED", "remainderAddress": "0xc354D97642FAa06781b76Ffb6786f72cd7746C97" } ``` Now we only need to execute the following command: ``` npx truffle --network regtest exec tasks/deploy-collector.js --collectorConfig="deploy-collector.input.json" --outputFile="output.json" The collector is ready and can start receiving fees. - 3) Allow Tokens * RIF Relay only accepts whitelisted tokens. Locally there is a script that can be use to whitelist the tokens. ``` npm run allowTokens 0x726ECC75d5D51356AA4d0a5B648790cC345985ED --network regtest ``` > The allowTokens script assumes that you are in Regtest and uses the account[0] as the owner of the contracts and that’s important because only the owner can allow tokens on the contracts. There are multiple reasons to just allow whitelisted tokens but the main one is to ensure that RIF Relay is just accepting tokens that represent value for the sponsor. - 4) Run RIF Relay Server * Once we have all the on-chain components, we will continue with the off-chain components. This process is done with the [RIF Relay Server](https://github.com/rsksmart/rif-relay-server). Prior starting the Relay Server, we need to update the configuration file, we save the configuration file as **server-config.json**. Below is an example using the RSKj node locally and the contracts that we just deployed. ```json { "url": "localhost", "port": 8090, "relayHubAddress": "0xE0825f57Dd05Ef62FF731c27222A86E104CC4Cad", "relayVerifierAddress": "0x5159345aaB821172e795d56274D0f5FDFdC6aBD9", "deployVerifierAddress": "0x1eD614cd3443EFd9c70F04b6d777aed947A4b0c4", "gasPriceFactor": 1, "rskNodeUrl": "http://127.0.0.1:4444", "devMode": true, "customReplenish": false, "logLevel": 1, "workdir": "/home/user/workspace/relay" } ``` > The Relay and Deploy verifier are using the contracts from the Smart Wallet section in the summary. Each key of the file have the following meaning: - **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. - **relayVerifierAddress**: is the relay verifier contract address. - **deployVerifierAddress**: is the deploy verifier contract address. - **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. Now we can start the server with the following command: ``` npm run start ``` > By default the server will use the file server-config.json in the root directory. > The start command can receive the path of the configuration file as parameter, more information can be found in the [RIF Relay Server](https://github.com/rsksmart/rif-relay-server#system-usage) documentation. At this point the server should be running and ready to start processing transactions, however, we still need to register all the off-chain components in the Relay Hub. To do the registration process, the following command needs to be executed: ``` npm run register ``` > The command needs to be execute in a different terminal since it needs the server to be running to perform the registration. > The register command can receive multiple parameters to simplify the interaction, more information can be found in the [RIF Relay Server](https://github.com/rsksmart/rif-relay-server#server-registration) documentation. The register process performs the following actions: - Stake the Relay Manager - Add the Relay Worker - Register the Relay Server Now the server is ready to start processing transactions and a ready message will be on the console. - Testnet * Below are the steps to start using RIF Relay on Testnet. All the components will be interacting with the RSK Testnet (https://public-node.testnet.rsk.co). [](#top "collapsible") - 1) Contracts Deployment * On Testnet the [contracts](https://developers.rsk.co/rif/relay/contracts/) are already deployed or you can deploy your own contracts. * All the necessary tools to do the deployments were included in [RIF Relay Contract](https://github.com/rsksmart/rif-relay-contracts). To start the process on Testnet we need an account with funds. The funds retreival con be done from the [tRBTC Faucet](https://faucet.rsk.co/). ``` npx truffle migrate --network testnet ``` > Take in consideration that the testnet network needs to be configured in the truffle.js file. - 2) Collector Contract * In principle, any number of Collector contracts can be deployed and used. This does not automatically occur alongside the deployment of the rest of the Relay contracts during the execution of migrations since usage of the Revenue Sharing feature is optional. For an overview of the Collector contract please see [the corresponding architecture document section](/rif/relay/architecture/#collector). Before deploying a Collector contract please make sure that: 1. The token chosen for this contract matches the one used for relayed transaction fees. **Any tokens other than the one set at the time of the Collector deployment which are sent to the contract will be impossible to retrieve, including the native token**. 2. The owner of the Collector contract has been chosen (be it a multisig contract address, a regular contract address or an EOA). This does not need to match the address deploying the contract, but please note that if there are no means of signing Collector contract function calls with the owner address **all revenue sharing funds will be permanently locked in the contract**. 3. Partners and their shares have been defined correctly. This means that beneficiary shares must collectively add up to 100. As with the previous point, any tokens sent to an address without its private key held by its beneficiary will be lost. For an example of a structurally valid revenue shares definition see [this deploy collector task input sample](https://github.com/rsksmart/rif-relay-contracts/blob/PP-94/revenue-sharing-model/deploy-collector.input.sample.json). * - 3) Allow Tokens * RIF Relay only accepts whitelisted tokens. To whitelist a token on Testnet we need to execute the `acceptToken(address token)` on the Relay Verifiers: * `SmartWalletDeployVerifier` * `SmartWalletRelayVerifier` > The contract execution needs to be done by the owner that is the account that did the deployment. There are multiple reasons to just allow whitelisted tokens but the main one is to ensure that RIF Relay is just accepting tokens that represent value for the sponsor. - 4) Run RIF Relay Server * Once we have all the on-chain components, we will continue with the off-chain components. This process is done with the [RIF Relay Server](https://github.com/rsksmart/rif-relay-server). Prior starting the Relay Server, we need to update the configuration file, we save the configuration file as **server-config.json**. Below is an example using the RSKj node locally and the contracts that we just deployed. ```json { "url": "localhost", "port": 8090, "relayHubAddress": "0xe90592939fE8bb6017A8a533264a5894B41aF7d5", "relayVerifierAddress": "0xDe988dB9a901C29A9f04050eB7ab08f71868a8fc", "deployVerifierAddress": "0x345799D90aF318fd2d8CbA87cAD4894feF2f3518", "gasPriceFactor": 1, "rskNodeUrl": "https://public-node.testnet.rsk.co/", "devMode": true, "customReplenish": false, "logLevel": 1, "workdir": "/home/user/workspace/relay" } ``` > The [contracts](https://developers.rsk.co/rif/relay/contracts/#primary-contracts) that are been used, are the primary one that does not have support for CustomSmartWallet. Each key of the file have the following meaning: - **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. - **relayVerifierAddress**: is the relay verifier contract address. - **deployVerifierAddress**: is the deploy verifier contract address. - **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. Now we can start the server with the following command: ``` npm run start ``` > By default the server will use the file server-config.json in the root directory. > The start command can receive the path of the configuration file as parameter, more information can be found in the [RIF Relay Server](https://github.com/rsksmart/rif-relay-server#system-usage) documentation. At this point the server should be running and ready to start processing transactions, however, we still need to register all the off-chain components in the Relay Hub. To do the registration process, the Relay Manager and Worker must have funds. To obtain the addresses we need to execute the command: ``` curl http://<SERVER_URL>/getaddr ``` > The command needs to be execute in a different terminal since it needs the server to be running to perform the request. ```json { "relayWorkerAddress": "0xabf898bd73b746298462915ca91623f5630f2462", "relayManagerAddress": "0xa71d65cbe28689e9358407f87e0b4481161c7e57", "relayHubAddress": "0xe90592939fE8bb6017A8a533264a5894B41aF7d5", "minGasPrice": "6000000000", "chainId": "31", "networkId": "31", "ready": false, "version": "2.0.1" } ``` Send at least 0.001 tRBTC to the Worker and Manager. Now execute the command the register command. ``` npm run register --network <RSKJ_NODE_URL> --hub <RELAY_HUB_CONTRACT_ADDRESS> -m <secret_mnemonic> --from <ADDRESS> --funds <FUNDS> --stake <STAKE> --relayUrl <RELAY_URL> ``` > The register command can receive multiple parameters to simplify the interaction, more information can be found in the [RIF Relay Server](https://github.com/rsksmart/rif-relay-server#server-registration) documentation. The register process performs the following actions: - Add the Relay Worker - Register the Relay Server Now the server is ready to start processing transactions and a ready message will be on the console. - Mainnet * TBD

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully