Erick de Moura
Cartesi
Published in
10 min readDec 25, 2020

--

In this article, you will learn how to run your own Cartesi node and participate in the staking system. By running a node and staking, you will receive CTSI rewards from Cartesi’s Mine Reserve for each block you produce.

Before staking you must be aware of how the PoS system works, the involved setup and operation costs, and your staking options. Additionally, refer to the FAQ to balance your expectations.

Cartesi’s system is meant to bootstrap a network of Cartesi nodes. It selects block producers randomly according to the amount they lock in the staking contract. In the current version, blocks are created empty, without transaction payload. In the future, with the release of Noether, DApps will be able to use the full-fledged sidechain to send transactions at high throughput and low cost. The path to Noether will include new version releases of the node reference software, requiring operators to upgrade their systems.

The staking system runs on top of Ethereum. Each block is claimed on-chain by its producer, requiring the node to spend gas to execute the corresponding transaction. As you set up a node to produce blocks for you, you need to fund it with enough ETH to complete the setup and also to produce blocks for some time. You can find the cost associated with each required transaction on Ethereum in the FAQ. More details on how to fund your node will be presented below.

If your node is down, offline, or with insufficient ETH funds, you will fail to produce blocks and therefore be unable to gain rewards. However, there is no slashing due to any node failure at the moment. Your principal is never at risk and you can always recover it from the staking contract at any time by using the Cartesi Explorer and the wallet you used to stake.
All rewards associated with blocks that your node produces are directly distributed to your personal ERC-20 wallet and therefore not subject to any locking.

Further information:

  • General frequently asked questions about staking and mining are covered on the FAQ.
  • On mining reserve and rewards, click here.
  • On the Noether side chain, click here.
  • On the staking algorithm and source code, go to the Github repository.

1. Install Docker

Start by installing Docker Engine on your computer: https://docs.docker.com/engine/install/

2. Run Cartesi's node

Open a terminal and run the following command lines. They will download, install, and run Cartesi’s reference node software.

docker pull cartesi/noether

And then:

docker run -it --rm --name cartesi_noether -v cartesi_wallet:/root/.ethereum cartesi/noether --url https://eth.cartesi.io --wallet /root/.ethereum/key --create --verbose

When the worker node starts, it creates a new Ethereum wallet, asking for an encryption password, and then polls the blockchain waiting for a user to hire it. It is very important to remember the password you set as there is no way to decrypt the node wallet without it. You are also strongly encouraged to backup your node’s wallet as described in section 8. Once the node is initialized, you should see output log lines like the following in your console:

INFO: starting worker 0x8394c1edbde8295cc5a6393738f222ec567d5027

The unique address you see should be kept confidential until you hire your node.

It is highly advised that you change the default Ethereum Gateway to a more reliable one, you can check section 6 below to do that. If you want to use a hosted service and set up a node very easily, check section 7.

3. Using Cartesi Explorer to stake

Before you start, make sure to use one of the following browsers: Chrome or Firefox. Brave and MS Edge also support Metamask but we have observed some unexpected behaviors with some users.

Go to the Cartesi Explorer URL: https://explorer.cartesi.io

Find the blue button on the header of the website. It should read “Install Metamask” in case Metamask isn’t installed on your browser yet. If that’s the case, head over to https://metamask.io and install it.

Once Metamask is installed, the blue button on the header should display the text “Connect To Wallet”. Click the button and select the Ethereum account holding the CTSI you intend to stake. Remember you also need enough ETH funds in the same wallet to later transfer to your node, as we will instruct below.

Now, navigate to the “staking” page: https://explorer.cartesi.io/staking

First, you will need to set an allowance. This is going to be the maximum amount of CTSI that Cartesi’s staking contract will be able to receive from your personal account. Enter the total value you wish to allow the CTSI staking contract to hold and click “Approve” as shown below. In case you want to increase your stake in the future, you may want to initially allow a higher value so you don’t need to perform a new approval transaction later. There is also an option to check for “infinite” approval, so you won’t ever need to increase the limit again.

Confirm the transaction on Metamask and wait until the allowance transaction is confirmed on-chain. In the end, you should see the value you entered displayed back to you, or like in the example below if you selected "Infinite Approval".

Next, enter the amount you want to stake under “Amount to stake” and click “Stake”. Confirm on Metamask and allow some time for the transaction to be confirmed on Ethereum.

When that happens, the funds you stake will go to a maturing state. It takes hours for your staking to achieve maturity. You will see them in the “Maturing” bar with a countdown timer.

Be warned that whenever you have a non-zero maturing balance and you try to stake more, the maturing timer restarts with the new funds added to the previous maturing balance.

After six hours you would see your “Maturing” balance zero and the staked funds appearing in the “Staked” bar. Only at that point are you effectively eligible to produce blocks.

4. Hire the node

At this point, your node is running and you have already staked your funds using Cartesi Explorer.

Now, you need to hire this node so it will start working for you. By doing so, your account is exclusively associated with the node. That will also authorize the staking contract to accept calls from your node on your behalf.

First, go to the terminal where you started the node and look for the node address, where it says:

starting worker 0x8394c1edbde8295cc5a6393738f222ec567d5027

Of course, you will see a different hash, representing your own address. Select and copy your node’s address to the clipboard (Ctrl-C or Command-C).

Still, on the staking page (https://explorer.cartesi.io/staking), click on the field “Click to hire node”. It will expand the panel and show you a field where you need to paste the node address you copied before.

Paste the address in the field (Ctrl-V or Command-V) and wait for the process to conclude. After a short while you should see the following fields appearing in the same panel:

At this point, you need to specify the amount of ETH you want to give to your node. The node holds a separate Ethereum account and key pair, and only spends your ETH to accept being hired during setup (only once) and then to produce blocks. That means you only incur transaction fee expenses when you are rewarded with CTSI.

Expect to spend around 120,000 gas every time your node produces a block.
As your node successfully produces more and more blocks, its ETH balance will decrease and may need to be replenished. You can always come back to this screen to top up your node ETH. You might want to take a look at the FAQ about how much ETH to fund your node with.

The day you don’t want to participate in the staking you can click on the link “Retire” and all remaining ETH funds held by the node will be transferred to your personal Ethereum account. Notice that the node needs to be active, so it can read the “Retire” transaction on the blockchain and respond by sending the funds back to you.

Once that node is retired, you cannot reuse it. If you want to participate in the system at a later time, you will need a new node with a new address.

5. Unstaking

When you want to withdraw your funds, use the “Unstake” tab and enter the amount you want to recover.

Bear in mind that your funds take 48 hours to become unlocked. As you unstake your funds, they go to a releasing state and you see a timer displaying how much time is left for the unlocking. At the end of that time, the bar that started showing your “Releasing” amount, changes its title to “Released” and with that, you are given an option to withdraw your CTSI to your personal account. Once the withdrawal transaction is processed your CTSI is back to your wallet.

Be careful if you want to unstake more funds while you have a non-zero “Releasing” balance. In that case, the timer restarts with the new unstaking funds added to the previously “Releasing” balance.

6. Customizing your Ethereum node

To facilitate the node installation procedures, our reference software is configured to use Cloudflare’s Ethereum Gateway by default, as it is free and requires no prior setup or account creation. In section 2 we instruct you to run:

docker run -it --rm --name cartesi_noether -v cartesi_wallet:/root/.ethereum cartesi/noether --url https://eth.cartesi.io --wallet /root/.ethereum/key --create --verbose

This will launch a Docker container named `cartesi_noether`, and also create a local Docker volume called `cartesi_wallet`.

The container connects to an Ethereum node specified with the ` --url` parameter, which in the command above is `eth.cartesi.io`, a CNAME for Cloudflare Ethereum Gateway.

Any Ethereum node can be used by replacing that by a local `geth` URL or another service provided by a third-party, like Infura or Alchemy.

For example, if in the case of using a remote Infura node you will run:

docker run -it --rm --name cartesi_noether -v cartesi_wallet:/root/.ethereum cartesi/noether --url https://mainnet.infura.io/v3/<project_id> --wallet /root/.ethereum/key --create --verbose

Where <project_id> must be replaced by your Infura’s project id. It is highly advised that you replace the default Ethereum node URL with a reliable one as Cloudflare Ethereum Gateway is very unstable.

7. Running on Heroku

If you want a quick and easy VPS alternative, here it is.

There is a simple way to use Heroku to run a node. You first need to create an account. A free account will give you 550 dyno hours per month which is not enough to run the node 24x7. You should add a credit card to your account to get more 450 hours/month.

Once you've set up your Heroku account, click here. That will take you to a screen that will create the node for you, similar to the one below.

You need to enter a name in the App name field, for instance, (your name)-cartesi. Then you scroll down and click the button "Deploy app". You are set!

It will take some seconds for Heroku to build the app. When it is complete, you should be presented with something like the screenshot below.

At this point, your exclusive node is already running and you need to find out its Ethereum address. For that, you click on the button "Manage App", which takes you to the page of your App. On the top menu, select "More" and then "View logs". You will find the worker (node) address in there. Copy that address and use it on the staking page of Cartesi Explorer, as explained above.

Heroku does not provide persistent disk storage, so we can’t store the encrypted wallet on disk. Instead, we use a random seed created by Heroku during deployment, and stored in the application environment variables. Keep in mind that this is not the safest solution, but once the node is hired it will only work for you (its sole owner). The funds in the node should be kept at a level just for block production.

It is highly advised that you replace the default Ethereum node URL with a reliable one as Cloudflare’s one is very unstable. You can use a third-party service like Infura and Alchemy or even your own Ethreum node if you have one. You can check the procedure to update your node’s Ethereum node URL on this FAQ.

8. Backing up your node's wallet

Your node’s wallet contains the ETH you fund it with during your mining operation and it also has the address used to hire and authorize your node to produce blocks on your behalf.

Therefore, it is a good idea to backup its wallet so, in case something happens to your node, you will be able to access its wallet fund and also create a new node to replace it without the need to spend more ETH on setup. You can find the procedure to backup your node’s wallet on the FAQ.

For further information check the Noether repo at https://github.com/cartesi/noether

Doubts? Find us on Discord: https://discordapp.com/invite/Pt2NrnS
Bring your question to the ctsi-reserve-mining channel and we will do our best to help you out.

Happy Staking!

Disclaimer: By running the above software, you are agreeing to the open source licenses present on our Github. For more information, please see https://github.com/cartesi/noether/blob/master/LICENSE.

Although the software has been tested and audited, please run at your own risk.

--

--