How to get started on RSKj for your dApp project RSK is a secured smart contract platform, thanks to merged mining with the Bitcoin network, allows Bitcoin miners to mine RSK’s sidechain using the same work for both. merged mining This is the basis for RSK’s extremely high hash rate, which is approximately 63% of the Bitcoin network’s hashrate currently; and therefore the reason that RSK is the most secure smart contract platform. is the software used to run nodes on the RSK network. You can find it on Github: . RSKj 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 locally to connect to the public RSK networks - RSKj Connect to RSK Mainnet . Connect to RSK Testnet Also, check out an alternative to connecting to the . public nodes Furthermore, you can run RSKj in a environment, without connecting to any public network using the localhost-only RSK Regtest Interacting with a dApp To interact with a dApp, you can use a , for wallets that support RBTC and RIF tokens. Web3 enabled wallet software Configure MetaMask to connect to RSK To configure Metamask to connect to RSK, see the step by step guide demonstrating . 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! how to interact with a DApp on RSK using Remix and MetaMask 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 RSK Testnet Stats You can also check the status of a particular transaction and deployed smart contracts, using: RSK Explorer RSK Testnet Explorer See the address and this address: 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. RIF Smart Contract 0xc218fc2b765ab321a907d6125fe7763e2eaec8e16dd4a72e1a4829a9baa2451a 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 for further details. fast payments Send JSON-RPC requests To send JSON-RPC requests, see list of that RSK currently supports. JSON-RPC Methods Obtain test tokens You can use the faucet to get test tokens (tRBTC) for use in RSK test network. Obtain tRBTC token in the tRBTC Faucet Obtain tRIF token in the . tRIF Faucet 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 is the best fit for these needs. in Regtest mode 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 Download RSKj JAR Navigate to . RSKj’s releases page From the release, download a file whose name looks like , where * is replaced by the release tag name, for example . latest rskj-core-*.jar 2.2.0-PAPYRUS Run RSKj To run RSKj, copy the following commands below, and paste in terminal where is located. rskj-core-*.jar java -cp <PATH-TO-THE-RSKJ-JAR> \ -Drpc.providers.web.cors=* \ co.rsk.Start \ --regtest The above command runs RSKj connected to Regtest, which is a 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. localhost-only If you see no output - that is a good thing: Its output is directed to a log file. Note: Remember to replace <PATH-TO-THE-RSKJ-JAR> 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 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 file: truffle-config.js (1) Set a variable to contain a valid BIP-39 mnemonic phrase testnetSeedPhrase (2) Set a variable to contain the gas price you wish to use denominated in Wei. gasPriceTestnet (3) In the exported object, set the value of config.networks.testnet to be the following. config 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, }, 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 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 module in your config file: debug modules = [ ... { : , : , : , }, ... ] "name" "debug" "version" "1.0" "enabled" "true" Then, you can execute the RPC method passing the transaction ID as a parameter, like in this example: curl \ -X POST \ -H \ --data '{ : , : , :[ ], : }' \ http://localhost: "Content-Type:application/json" "jsonrpc" "2.0" "method" "debug_traceTransaction" "params" "0xa9ae08f01437e32973649cc13f6db44e3ef370cbcd38a6ed69806bd6ea385e49" "id" 1 4444 You will get the following response (truncated for brevity): { ... : , : , : , ... } "result" "08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001e536166654d6174683a207375627472616374696f6e206f766572666c6f770000" "error" "" "reverted" true Finally, convert from hexadecimal to ASCII, to obtain a readable message: result Ãy SafeMath: subtraction overflow 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. Remote Procedure Calls (JSON-RPC) JSON-RPC is available over two network transport protocols: and HTTP WebSockets Configuring and using RPC over HTTP Configuring and using RPC over WebSockets Note that 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 . RSK public nodes 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 Kudos Thanks to and for their help in reviewing this guide! Brendan Graetz Diego Masini