DEV Community

Owanate Amachree
Owanate Amachree

Posted on • Updated on

Beginner's Guide to Getting Started with RSK Blockchain Node

RSK is a secured smart contract platform, thanks to merged mining with the Bitcoin network, merged mining allows Bitcoin miners to mine RSK’s sidechain using the same work for both. This is the basis for RSK’s extremely high hash rate, which is approximately 63% of the Bitcoin network’s hash rate currently; and therefore the reason that RSK is the most secure smart contract platform.

RSKj is the software used to run nodes on the RSK network.
You can find it on Github:
rsksmart/rskj.

Interact with the RSK network

You can interact with the RSK network
in various ways without running your own node.

Connect to RSKj

You can run
RSKj locally to connect to the public RSK networks -

  1. Connect to RSK Mainnet
  2. Connect to RSK Testnet.

Also, check out an alternative to connecting to the
public nodes.

Furthermore, you can run RSKj in a localhost-only environment, without connecting to any public network using the RSK Regtest

Interacting with a dApp

To interact with a dApp, you can use a Web3 enabled wallet software, for wallets that support RBTC and RIF tokens.

Configure MetaMask to connect to RSK

To configure Metamask to connect to RSK,
see the step by step guide demonstrating
how to interact with a DApp on RSK using Remix and MetaMask.
Both Remix and MetaMask are tools that were originally built for Ethereum,
and thanks to RSK's comaptibility
(both in its Virtual Machine executing smart contracts,
and in its communications protocol using JSON-RPC),
these tools work on RSK too!

We'll use them to create and deploy a simple smart contract on RSK’s Testnet.

Check the status of the RSK network

To check the status of the RSK Network in real-time, use:

RSK Mainnet stats

You can also check the status of a particular transaction and deployed smart contracts, using:

See the RIF Smart Contract address and this address: 0xc218fc2b765ab321a907d6125fe7763e2eaec8e16dd4a72e1a4829a9baa2451a is a transaction hash. You will notice that this type of transaction is perfmormed by neither an externally owned account or a smart contract. In fact it is a REMASC transaction.

Reward Manager Smart Contract (REMASC) is a pre-compiled smart-contract that is executed on every block and has the responsibility to fairly distribute rewards collected from transaction fees into several participants of the network.

From: REMASC architecture

This type of transaction is found in neither Bitcoin nor Ethereum, but is a key component of how the RSK network is able to achieve block times that are frequent enough to enable smart contract based decentralised applications, and while being merge-mined with Bitcoin.
See fast payments for further details.

Send JSON-RPC requests

To send JSON-RPC requests, see list of
JSON-RPC Methods
that RSK currently supports.

Obtain test tokens

You can use the faucet to get test tokens (tRBTC) for use in RSK test network.

Getting Started

If none of the above fits the bill for you,
you will need to run your own RSK node.

Especially if you are developing smart contracts,
developing DApps, or participating in a hackathon,
you are likely to want to iterate fast, and therefore need quicker feedback loops.

Running RSKj in Regtest mode is the best fit for these needs.

System Requirements

The following are the minimum requirements needed to install an RSKj node.

  • 2 cores
  • 8 GB RAM
  • 50 GB storage
  • OS x64

Install Java

The RSKj executable is a Java Archive file (JAR file),
and requires Java to run.
See guide on how to install the Java 8 JDK.

Java downloads page

Download RSKj JAR

Navigate to RSKj's releases page.

From the latest release, download a file whose name looks like rskj-core-*.jar, where * is replaced by the release tag name, for example 2.2.0-PAPYRUS.

Download RSKj core

Run RSKj

To run RSKj, copy the following commands below, and paste in terminal where rskj-core-*.jar is located.

java -cp <PATH-TO-THE-RSKJ-JAR> \
  -Drpc.providers.web.cors=* \
  co.rsk.Start \
  --regtest
Enter fullscreen mode Exit fullscreen mode

The above command runs RSKj connected to Regtest, which is a localhost-only network, clears the database each time the node is started, and enables both CORS. These are the most useful and commonly used flags and options for when you are developing or testing smart contracts and DApps.

If you see no output - that is a good thing: Its output is directed to a log file.

Note: Remember to replace with the path which contains the downloaded jar file. See example command below.

java -cp /Users/owanate/Downloads/rskj-core-2.2.0-PAPYRUS-all.jar \                   
  -Drpc.providers.web.cors=* \
  co.rsk.Start \
  --regtest
Enter fullscreen mode Exit fullscreen mode

Developer Tools

Truffle

Here is how you would configure Truffle to connect to the RSK Testnet.

See below code for how to implement this in a Truffle project.

In your truffle-config.js file:

(1) Set a variable testnetSeedPhrase to contain a valid BIP-39 mnemonic phrase

(2) Set a variable gasPriceTestnet to contain the gas price you wish to use denominated in Wei.

(3) In the exported config object, set the value of config.networks.testnet to be the following.

testnet: {
      provider: () => new HDWalletProvider({
        mnemonic: {
          phrase: testnetSeedPhrase,
        },
        providerOrUrl: 'https://public-node.testnet.rsk.co/',
        derivationPath: "m/44'/37310'/0'/0/",
        // Higher polling interval to check for blocks less frequently
        pollingInterval: 15e3,
      }),
      // Ref: http://developers.rsk.co/rsk/architecture/account-based/#chainid
      network_id: 31,
      gasPrice: gasPriceTestnet,
      networkCheckTimeout: 1e6,
      timeoutBlocks: 100,
      // Higher polling interval to check for blocks less frequently
      // during deployment
      deploymentPollingInterval: 15e3,
    },
Enter fullscreen mode Exit fullscreen mode

This enables you to understand Truffle’s default configuration values (based on Ethereum),
in particular surrounding polling intervals. Using these two relatively new configuration options allows you to configure Truffle to better connect to an RSK node.

For more details, see
Configuring Truffle to RSK.

Debugging

Need to debug transactions in RSK?

See an example of how to debug transactions in an RSK Network on Stackoverflow

debug transactions in an RSK Network on stackoverflow

If your contract emits messages in the reversions, then you can find them out by using debug_traceTransaction.

Note that the debug RPC module is enabled by default in RSK config, but this is disabled on public nodes.

Furthermore, the RSK public nodes do not expose this feature, and you must run your own node in order to do so.

The following assumes that you have a local node running with RPC exposed on port 4444.

First, you need to enable debug module in your config file:

modules = [
    ...
    {
        "name": "debug",
        "version": "1.0",
        "enabled": "true",
    },
    ...
]
Enter fullscreen mode Exit fullscreen mode

Then, you can execute the RPC method passing the
transaction ID as a parameter, like in this example:

curl \
    -X POST \
    -H "Content-Type:application/json" \
    --data '{"jsonrpc":"2.0","method":"debug_traceTransaction","params":["0xa9ae08f01437e32973649cc13f6db44e3ef370cbcd38a6ed69806bd6ea385e49"],"id":1}' \
    http://localhost:4444
Enter fullscreen mode Exit fullscreen mode

You will get the following response
(truncated for brevity):

{
    ... 
    "result": "08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001e536166654d6174683a207375627472616374696f6e206f766572666c6f770000",
    "error": "",
    "reverted": true,
    ...
}
Enter fullscreen mode Exit fullscreen mode

Finally, convert result from hexadecimal to ASCII,
to obtain a readable message:

Ãy  SafeMath: subtraction overflow
Enter fullscreen mode Exit fullscreen mode

RPC

Remote Procedure Calls (JSON-RPC)
are the primary interface through which RSK nodes
communicate over the network.
RSK's JSON-RPC has a high level of compatibility with Ethereum's JSON-RPC.

JSON-RPC is available over two network transport protocols: HTTP and WebSockets

Note that RSK public nodes
do not expose WebSockets, they are HTTP only.
To work around this, you may either
run your own RSK node,
or use a third-party node provider,
such as Getblock.

Wrap up

In this article, we interacted and connected with the different public RSK Networks, Configured Metamask to connect to RSK, Downloaded and ran an RSK Node in regtest network.

Thanks for reading!

For more tutorials and guides, check out the RSK/RIF knowledgebase in DevPortal.

This article was originally published on Hackernoon

Kudos

Thanks to Brendan Graetz and Diego Masini for their help in reviewing this guide!

Top comments (0)