This article is part of a POA tutorial series:
- (POA Guide - Part 1) - Develop and deploy a smart contract
- (POA Guide - Part 2)- Bridge assets between a sidechain and a mainchain
- POA - Part 3 - Meta-transaction [Coming soon]
POA Network is an Ethereum-based platform that offers an open-source framework for smart contracts. POA Network is a sidechain to Ethereum utilizing Proof of Authority as its consensus mechanism. POA provides developers with the flexibility to code in Ethereum standards with the added benefits of POA Network’s solutions to scalability and interoperability in blockchain networks.
POA has transaction fees just like the Ethereum mainnet, but in comparison to the Ethereum mainnet where fees are paid in Ether, the POA blockchain requires fees in its native currency called POA Token, this token can be obtained on a Crypto Trading platform like Binance.
POA currently has two networks up and running:
- POA Core: The main network requiring POA token
- POA Sokol: A test network requiring POA Sokol token
For the purpose of this tutorial, we will use the POA Sokol network.
In this first step, we’re going to learn how to connect our Metamask wallet to a POA test network called Sokol and how to fund the account with Test POA tokens.
Unlock your Metamask extension
Go to Settings, enter the following new RPC URL https://sokol.poa.network and click on Save
Metamask should switch to this new private network
Note: A dedicated Browser extension (only Chrome) for POA and very similar to Metamask can also be used: Nifty
In Metamask, copy your account address
Go to the POA Sokol Faucet
Click on Request 0.5 POA
- You can your account balance in Metamask or also see in the POA Sokol Explorer if the transaction went through.
The second step consists in writing a very simple Smart Contract in Solidity and deploy it on the POA Sokol Network using Truffle framework.
- Install Truffle on your machine
$ npm install -g truffle
- Initialise your Truffle project
$ truffle init
Let’s now write a simple Smart Contract that increments and store a counter
Create a file in
contracts/Counter.soland paste the following Solidity code
pragma solidity ^0.4.20;
You can verify that your code compiles correctly with the following command
$ truffle compile
Now, we need to create a deployment script
Create a file in
migrations/2_deploy_contracts.jsand paste the following code
var Counter = artifacts.require("./Counter.sol");
- Finally we need to configure the connection to the POA Sokol network as well as our wallet info
- truffle-hdwallet-provider enables to sign transactions for addresses derived from a 12-word mnemonic
- dotenv is a module to configure environment variables
$ npm install truffle-hdwallet-provider dotenv --save-dev
- Copy your mnemonic from your Metamask wallet: Settings / Reveal Seed Words
DO NOT SHARE THOSE 12 WORDS WITH ANYBODY
- Create a
.envin the Truffle project and copy the mnemonic like this
MNEMONIC="COPY HERE YOUR 12 MNEMONIC WORDS YOU DO NOT WANT TO SHARE"
- Open the file
truffle.jsand add the following configuration
- Run the deployment to the POA Sokol network
$ truffle migrate --network poa
In the next step, we will develop a dApp using React, Web3 and Truffle to interact with the Smart Contract previously deployed on the POA Sokol network.
- Initialise a React project
$ npx create-react-app frontend
- Install the necessary dependencies
- truffle-contract: is an Ethereum Smart Contract abstraction library
$ npm install truffle-contract web3 --save
- Edit package.json and add the following line under the scripts section to access the Truffle contract artifacts from the webapp
The full code of this file is available here: package.json
- Open an edit src/App.js
- Connect to the node with web3
import Web3 from 'web3'
- Use truffle-contract to load the Truffle artefacts and interact with the smart contract
import TruffleContract from 'truffle-contract'
The full code of this file is available here: App.js
- Create a link to the Truffle JSON artefacts
$ npm run link-contracts:linux:darwin
- Start the webserver
$ npm start
If Metamask is unlocked and connected to the Solok network, The web3 provider connects automatically to the node and retrieves the counter value. When the user clicks on “Increment”, Metamask pops up to sign a transaction and send it to the POA Solok network.
Network ID: 77
JSON-RPC Endpoint: https://sokol.poa.network
Network Status: https://sokol-netstat.poa.network/
Network ID: 99
Network Status: https://core-netstat.poa.network/