This box comes with everything you need to start using Truffle on RSK Blockchain. It includes network configurations for Mainnet, Testnet and the SimpleStorage contract as an example to deploy.
RSK is an open source platform for Ethereum compatible smart contracts based on the Bitcoin network.
- NPM (Node Package Manager) Node.js and NPM are needed, though both are usually installed at once.
Go to Node.js if you need to install it.
- Truffle
Install Truffle globally
npm install -g truffle
- Create a new folder.
For example, create the folder
rsk-starter
. Navigate to the folder in the terminal.
mkdir rsk-starter
cd rsk-starter
- Run the unbox command. It can take some time, as this will install all necessary dependencies.
truffle unbox rsksmart/rsk-starter-box
This is the result using Windows OS:
Truffle has an interactive console that also spawns a development blockchain. This is very useful for compiling, deploying and testing locally.
- Run the development console. This command is successful if you see a list of 10 accounts, a mnemonic and the command prompt is now
truffle(develop)>
truffle develop
You will now be in the truffle develop REPL with seeded accounts and their associated private keys listed.
Truffle Develop started at http://127.0.0.1:9545/
Accounts:
(0) 0x4579996629f631d5221c9ea0c3552f6dcff61e9e
(1) 0x52f43fccc4ffcbb9f0a57320401139ef4088093f
(2) 0xea7e59d8403587bdb1c12758eb33f82dc9e0a451
(3) 0x9eed1b59ac18360b67b7ef2a069f8c35ad62b009
(4) 0x064874a46fc29fd15736cc0c890276fe1dfb9ecc
(5) 0x2c612c461690ab601977595028ba1ed62e98d605
(6) 0x50a317d18a78e4ad8491c0696582da35ba30b12a
(7) 0xdf68b82ac51d21c731b8aa3c9c1d65c62ffb1b75
(8) 0x018c7c87900304eeff2f852def58776b920b9da2
(9) 0xdc2fe4385c54349c0303e448333a5de1131bc88e
Private Keys:
(0) 0895ef2194a15575ac9e75c5c837853637af444442f7b64dcea60029e68df5f6
(1) 1ca9f748b4d92ca6b9ffcc4f0027a17189871f250666fa20c08bc901a6757174
(2) 97e256de57f8206741223fe20953d047429b85f8a0ed5ec00a459cbf6e5859c4
(3) 7dc0ba635a4fe0af8be559446f34be036bc2aa055a34d81337601ba929b1892c
(4) c2dc9ba56f683ba2090de3932ab991f60c6e08535d2a8ffcc4c3ddea4b9be2f8
(5) e4943ce248e556559f5b5e0cc097215a440ca2dafcaddef9fbad79bef58e028d
(6) fbe436944b525e468209299b0e35f93a287bc0c25411418f10a9c2292ccbca8f
(7) 0381515a5f83c9c97683a370383f45a4d2c8de61299d8a0e03c2313a5ace2457
(8) ed39e1a942bf3c48c744bd5282410c811c56dbbec2bd133d09c43cd005a31e7b
(9) 2dd9fbe98b5a4bad9f619e260f99db699d5b80b3081c0bc283647b576e44b89a
Mnemonic: butter mention wealth vicious fancy plastic treat title filter excess witness bus
⚠️ Important ⚠️ : This mnemonic was created for you by Truffle. It is not secure.
Ensure you do not use it on production blockchains, or else you risk losing funds.
- Take a look at the smart contract
SimpleStorage.sol
. You can check it out in foldercontracts
.
This smart contract has:
- A variable
storedData
to store a number - A function
get()
to return the number stored at variablestoredData
- A function
set()
to change the number stored at variablestoredData
- Compile and migrate the smart contract. Note inside the development console we don't preface commands with truffle.
To make sure you're in the development console, the command prompt must be
truffle(develop)>
compile
The compile output
should be similar to:
migrate
And the migrate output
should be similar to:
- Running contract tests.
Our box also comes with the file TestSimpleStorage.js
for testing the smart contract. You can check it out in the test
folder.
Run this command in the development console:
test
This test output
should be similar to:
NOTE: This box is the starting point for the RSK tutorial Using rsk-starter-box.
Truffle makes developing on RSK easier because we can configure custom networks for RSK. The networks are already configured in the truffle-config.js
file.
- Get an address using these instructions.
- For the RSK Testnet, get tR-BTC from our faucet.
- For the RSK Mainnet, get R-BTC from an exchange.
Gas is the internal pricing for running a transaction or contract. When you send tokens, interact with a contract, send R-BTC, or do anything else on the blockchain, you must pay for that computation. That payment is calculated as gas. In RSK, this is paid in R-BTC. The minimumGasPrice is written in the block header by miners and establishes the minimum gas price that a transaction should have in order to be included in that block.
To get the minimumGasPrice do the following steps:
-
Run this query using cURL:
Mainnet
curl https://public-node.rsk.co/ \ -X POST -H "Content-Type: application/json" \ --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest",false],"id":1}'
Testnet
curl https://public-node.testnet.rsk.co/ \ -X POST -H "Content-Type: application/json" \ --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest",false],"id":1}'
-
Find in the result the field minimumGasPrice
For more information about the Gas and minimumGasPrice please go here.
-
Copy your mnemonic to
truffle-config.js
// truffle-config.json const HDWalletProvider = require('@truffle/hdwallet-provider'); //Put your mnemonic here, be careful not to deploy your mnemonic into production! const mnemonic = 'A_MNEMONIC';
Please be aware that we are using
HDWalletProvider
with RSK Networks derivations path:- RSK Mainnet dpath:
m/44’/137’/0’/0
- RSK Testnet dpath:
m/44’/37310’/0’/0
For more information check RSKIP57.
- RSK Mainnet dpath:
-
Check the gas price of the network, and update
truffle-config.js
if necessary. -
Run the truffle console for any RSK network.
# Console for Mainnet truffle console --network mainnet # Console forn Testnet truffle console --network testnet
-
Compile and migrate the smart contracts. Note that inside the truffle console, we don't preface commands with truffle.
compile migrate
-
Another option is to run the below commands directly in the terminal, out of the truffle console.
truffle compile truffle migrate
- Go to tutorial
Go to the tutorial Using rsk-starter-box to learn how to interact with SimpleStorage.sol
. Also, we covered all the steps with more details, explanations, and images.
- Find more documentation
Check out the RSK developers portal.
- Do you have questions?
Ask in RSK chat.