Polkadot is an exciting new entry in the crypto space, but while it features an illustrious wiki full of minute details on its algorithms and overall philosophy, actual living examples are somewhat missing.
As I have been engaged in a development project on this new network, I would like to share some insights on setting up a basic development environment and getting started.
Like all other blockchains, a Polkadot app must first connect to the network via a gateway node: a machine that runs an instance of the blockchain software, Polkadot in our case. While this can be done in numerous ways, once you are connected, you need to play by the rules of such a network. In other words, every transaction you will be performing while developing your application will be treated as a “real transaction,” even if that is happening on a “testnet” of some sort, where coins have no value. It also means that your transactions will be visible to everyone on that same network, which is something that you may or may not want to. Most importantly, however, you need someone to send you actual coins to do anything. On a testnet, you can do that via a public faucet, but that usually requires registration of some sort, and constantly praying that the faucet will be up and running whenever you want it. As these public nodes are run and maintained by volunteers, I found the hard way that this was not always the case. So, long story short, we are going to create not only our own local node but our own local Polkadot blockchain, where we can credit ourselves with millions of DOTs.
There are many ways to do this, and the Polkadot wiki offers some good documentation. From the options available, I found it easier to opt for a Docker installation. If you are unfamiliar with Docker you can choose another type from the Wiki, but considering that Docker is fast becoming a must in the developer community, I would suggest that you learn all about it.
So, once you have Docker on your system, run the following command
docker run -p 9944:9944 parity/polkadot:v0.8.24 --name "Local" --rpc-external -external --alice --dev
Let’s deconstruct this command:
docker runYou are telling docker to run a container that is identified on DockerHub (the public repository for Docker containers) as parity/polkadot. Specifically, we ask it to run v0.8.24.
-p 9944:9944Forward all requests that come on local port 9944 to the container’s internal port with the same number. That is the default Polkadot node port so any pre-configured applications will have no problems connecting there.
--nameThis can be anything, but “Local” will do for now
--rpc-externalAllow for WebSocket connections
--devRun the node on “dev mode.” This means that it’s not going to sync with any particular network, but launch a new Polakdot network on your local machine.
--aliceCreate a small number of wallets with a lot of money! (Alice and Bob are standard names in cryptographic literature).
Once this is done, you will be running a Polkadot blockchain locally
The idea of course is to create your own applications that run on Polkadot networks, but the first step is to use someone else’s and check whether everything is set up correctly. Polkadot.js is an open-source project built on React.js that connects to any Polkadot network and performs all the basic actions that can be performed. There is a public installation that you can check for immediate access, but we will be running this locally because we are interested in the code-base itself and what it can teach us.
git clone https://github.com/polkadot-js/apps polkadot-js
yarn run start
Once the app is running locally (along with the Docker instance on the background) you can navigate to http://localhost:3000 where you should see the app’s interface.
With your development blockchain running on your local machine inside a Docker container, we just need to point our UI to it. Press on the list of available networks on the top left
From the options that you see, scroll down to the development list, open it up and select “Local node.” Usually, the IP and port numbers are correct as they are the default ones with which we launched our local node. But just in case, check them again. Then press “Switch” on the left of the close button.
You should see something like this. Notice that you have 8 wallets full of money! These do not exist in any public network, but only on your local blockchain. Still, you can send and receive money between them using the exact same functionality that you would on a real blockchain.
The concept behind this article is that once you have access to a live Polkadot system you can just read the code and learn from what is happening. By now you should have both the and the instance of the UI running locally. So let’s see what we can do by using these existing tools … (Part II coming soon).