Mining with Pantheon

In this post, I continue my series on Pantheon, the new Java-based Ethereum Client and today I will cover how to mine with Pantheon. I am a big fan of Java so I am super excited to write more about this new Java-based tool and explore all the enterprise ready features in future posts. To learn how to get started using Pantheon see my previous post:
Introduction to Pantheon — The Java Ethereum Client

In order to mine ether using Pantheon you will first need to create a wallet to store the funds which will be earned by our miner node. Pantheon doesn’t support key management inside the client so you will need to use a third party tool such as MetaMask, to create and manage your ethereum accounts. MetaMask is a Ethereum wallet that runs as a browser extension which makes the whole process of managing your Ethereum accounts super easy. Let’s start by using MetaMask to create an account.

Creating a Wallet Using MetaMask

1. Install the MetaMask plugin using Chrome

Navigate to
https://metamask.io
in your browser. On the home page, click on ‘Get chrome extension’ (or if you are using another browser click on the relevant link).

Click on ‘Add to Chrome’ and follow the rest of the prompts to complete the installation.

2. Create a new MetaMask wallet

After the MetaMask installation completes, click on the ‘Get Started’ button and then you will see this page. Click on ‘Create a Wallet’ to start the process of creating your first wallet.

Start by entering a new password for your MetaMask wallet, accept the terms and conditions and then click ‘Create’.

Follow the rest of the prompts to confirm your secret backup phrase and then you should see the MetaMask home screen.

3. Create a new ethereum account in MetaMask

On the MetaMask home screen, click on the circle icon in the top right and then click on ‘Create Account’.

Enter a name for your new account and then click on ‘Create’. In this example below, I have named the account ‘Pantheon Miner’. Note that creating a new account simply generates a new public/private key pair and address. Details of this account don’t actually get sent to any Ethereum network until you start using the account on that network to send some transactions. You can use the same account on multiple networks but ether earned on one network will be separate from ether earned on another network.

We can now see our new account in the MetaMask home screen and it shows that we currently have zero ether on the Main Ethereum Network (aka mainnet). You can select one of the other networks in the network dropdown in the top right and it will still show that we have zero ether. After running the miner we will see that value grow as we mine.

Next click on the address of the Pantheon Miner account (just below the ‘Details’ button) to copy the value to the clip board. We will be using this account address in the rest of the tutorial.

Mining on a Local Dev Network

Lets start by running a dev miner locally, earning some ether and then viewing our current balance in MetaMask. To start the miner run this command:

The ‘miner-coinbase’ argument tells Pantheon which Ethereum account to send the earned ether to. You will also need to set the ‘miner-enabled’ flag to start the miner. Notice that below, I have set the ‘miner-coinbase’ argument to the value of my Pantheon miner account which I previously copied to the clipboard. Running the command we can see the Pantheon node start up and start mining blocks. The blocks are being added very quickly because this is a dev network which is configured with a low mining difficultly by default:

Now open MetaMask again, and then click on the ‘Networks’ button in the top right and select ‘Localhost 8545’. MetaMask should successfully connect to your dev Pantheon node running locally.

Now that our Pantheon miner is running, we can now see that the ether in our account (on the local dev network) has already increased to 124 ether and continues to grow:

Mining on a Testnet

MetaMask supports connecting to any Ethereum network over JSON-RPC. In the ‘Networks’ tab, you can select from five different public Ethereum networks which include Mainnet, Robsten, Kovan, Rinkeby and Goerli. Note that in MetaMask, you can also connect to any other Ethereum network which is not in the ‘Networks’ dropdown list, by using the ‘Custom RPC’ option.
Mainnet is of course the real public Ethereum network which uses real ether, allows anyone to be a miner and uses the proof of work consensus protocol (similar to Bitcoin).
Ropsten is the test network which is the most similar to mainnet and also allows anyone to be a miner and uses the proof of work consensus protocol.
Kovan, Rinkeby and Goerli are test networks which use a consensus protocol called proof of authority which does not support mining. You can have ether sent to you from a faucet which requires you to prove your existence by posting a link on social media.

Running the Pantheon miner on the Ropsten network

Now lets setup Pantheon to mine ether on the Ropsten public testnet. To do so, run this command:

Don’t forget to set the directory for the blockchain data using the ‘data-path’ parameter. If you forget to set the data directory Pantheon will use the default directory which may already contain blockchain data from another network (in my case mainnet) and in that case Pantheon will exit with an error. I have also turned on the JSON-RPC http endpoint using the ‘rpc-http-enabled’ parameter so we can monitor the status of the node. When enabled the RPC endpoint listens on and only allows connections from localhost on port 8545 by default. We also need to set the ‘rpc-http-cors-origins’ parameter if we want to connect to the locally running Pantheon node using MetaMask.

We can see the node start running and start syncing the blockchain data from the network, it won’t start mining until the syncing has completed. At the time of writing, the Ropsten network has about 5700000 blocks which will take a long time to fully sync so I won’t be waiting around for this to complete.

Monitor the Pantheon syncing status

We can monitor the status of the sync by hitting the RPC eth_syncing method using curl:

Mining on Mainnet

Remember that Mainnet has even more blocks then the Ropsten network and will take even longer to sync the blockchain. I have not set the blockchain data directory location using the ‘data-path’ parameter in this case so Pantheon will store the mainnet block data in the default directory. As before I’ve set the ‘miner-coinbase’ parameter to the same ‘Pantheon Miner’ ethereum account address which I have been using previously.

Monitor and Configure Pantheon Mining using JSON-RPC

You can use the following JSON-RPC API methods to monitor and configure the Pantheon miner. To use these methods you will need to set ‘rpc-http-apis’ Pantheon parameter to include the value ‘miner’ and ‘eth’. If you forget to do this you will get an ‘Method not enabled’ error message returned.

1. miner_start

Use miner_start to start mining on a Pantheon node. This allows us to start the miner on a Pantheon node which is already running but not mining:

Summary

So that gives you a brief overview of how to mine using Pantheon. We successfully created an Ethereum account using MetaMask, and started a dev Pantheon node with mining and RPC enabled. After that we watched the ether in our account grow using MetaMask, as our dev miner added new blocks. We then we ran the command to start the miner and watched the data start to sync on both Ropsten and Mainnet. I also covered some of the JSON-RPC methods you can use to configure and monitor the Pantheon miner.
I hope you find this information helpful. Feel free to send me your comments or questions and don’t forget to subscribe if you want to follow my future posts here at Web3 Developer.

Article Author

0 Comments

Related Articles

Introduction to Pantheon — The Java Ethereum Client

Pantheon is the new Java Ethereum client which has recently been open sourced and is now production ready (v1.1 at the time of writing). The code was written in Java and aims to provide enterprises with an Ethereum client that has features such as stability, permissions and access control, privacy, ease of deployment and scalability. These are common requirements for business looking to use Ethereum in their technology stack. Pantheon is also mainnet-compatible, and includes features like consen

Sending Transactions to Pantheon

In this post I will be covering how to send transactions to the Pantheon Ethereum Client. Pantheon supports sending signed transactions but it doesn’t support wallet management so you will need to use third party tools to do the transaction signing for you. Transactions can be sent to Ethereum to transfer ether, to create a new contract or to interact with a contract. JSON RPC API You can interact with contracts using the eth_call or eth_sendRawTransaction JSON RPC methods. eth_call is used to g