In this tutorial, learn how to run a private ethereum blockchain and deploy your very own ERC20 token. We'll also cover getting real world data onto the blockchain and what oracles are. Finally we'll discuss ICO (initial coin offering) basics. We'll merely be scratching the surface of all the complexities involved in the blockchain world and is for beginners just starting out with blockchain development. I would encourage you to continue with your research once you have completed this tutorial
1. Setup Bootnode
A bootnode acts as an entry point and helps nodes find other participating nodes in the network. First create a bootnode key and start the bootnode service.
Make a note of the enode:// uri, we will use this when starting up the first node.
2. Create account(s)
Next we will create some accounts that we can work with on the blockchain. We'll specify the the initial amount for these accounts in the genesis file which initializes the blockchain. I'm using ./datadir to store the contents of the blockchain but you can specify whichever directory you want, just make sure you are consistent with the directory you choose
#!/bin/bash
geth --datadir=./datadir account new
3. Create genesis file and initialize blockchain
The ethereum genesis file will initialize the blockchain. It is here you can set the initial difficulty, start block, gas limit, initial account balances from previous step, and features. In the genesis config you specify the various features which all nodes participating in the blockchain must conform to.
Create a file called genesis.json and add the following contents
Make sure to replace the account address with the address that was generated in the second step. To find the address look in the ./datadir/keystore/ UTC file which was generated during account creation
4. Start the first ethereum node
Ensure you use the same value in the networkid parameter that you specified in the chainId field of the genesis file, replace datadir where you initialized the blockchain/created the accounts, and replace the enode uri with the uri from the first step. I wont go into full details of the other parameters since they are self explanatory
The geth console will tab complete for you. Enter the following and use tab to get a list of their respective commands. (a full list of commands is here)
admin.
debug.
miner.
personal.
txpool.
Deploy your first smart contract / ERC20 token
Solidity is the language in which ethereum smart contracts are developed. To keep things simple, we'll use the node package manager to install the solidity compiler and use truffle for compiling and deploying the contract to the blockchain
npm install -g solc
npm install -g truffle
1. Initialize truffle project
#!/bin/bash
mkdir MyERC20Token
cd MyERC20Token
truffle init
2. Create the contract / ERC20 Token
Create the file contracts/FixedSupplyToken.sol. For this tutorial I am using the code from bokkypoobah's github. At the time of this writing I used git commit id 97950a9e4915596d1ec00887c3c1812cfdb122a2
3. Create the migration
Create the file migrations/2_deploy_contracts.js
var ercContract = artifacts.require("./FixedSupplyToken.sol");
module.exports = function(deployer) {
deployer.deploy(ercContract);
};
4. Deploy the contract
You'll need to have at least one ethereum node mining and unlock your ethereum account to deploy the contract. Open your geth console and run
Once your account is unlocked and you see blocks being mined succesfully, you can deploy the smart contract. You should see something like this before you deploy.
Update the truffle-config.js in the root of the MyERC20Token folder and configure the network settings for your ethereum node. If you have followed through this tutorial, uncomment the development section under networks
...
development: {
host: "127.0.0.1", // Localhost (default: none)
port: 8545, // Standard Ethereum port (default: none)
network_id: "15", // Any network (default: none)
},
...
Verify that truffle can succesfully connect to your ethereum node.
#!/bin/bash
truffle test
If everything checks out, compile and deploy the contract.
#!/bin/bash
truffle compile
truffle migrate
Interacting with smart contracts
We'll interact with the contract from the truffle console. Lets check the total supply, account balance, and transfer some tokens between accounts.
Oracles are what brings real world data onto the blockchain and come in many different shapes and sizes. For example, an oracle might be a service running on your computer, an individual, or even an entire organization. Typically organizations or groups of organizations will try to reach a consensus on the data before publishing it to the blockchain, these are known as consensus oracles. The data on the blockchain is only as good as the oracles that generate the data. So while the data on the blockchain data has integrity once its published, we must instill a sense of trust on the oracles generating that data. It's paradoxical to think that for a trustless blockchain system to operate it depends on a trusted data source. This problem is known as the oracle paradox and as of this writing there isn't a bullet proof solution that effectively addresses this. Consensys has been working towards a solution to this problem and you can find out more here. They are one of the many trying to solve this paradox. Many believe that once this problem is solved there will a breakthrough with massive scale adoption of blockchain technologies.
For beginners its typically fine to run an oracle from a single server. Just keep in mind that if that server is compromised then you and others may no longer want to trust the data being published.
Initial coin offering (ICO)
ICOs are one way of raising capital for your project or startup and there are a lot of factors to take into consideration before launch. When you start an ICO you are typically asking for investors to trade fiat, cryptocurrency, or other services in exchange for your coin. Your first order of business should be procuring a whitepaper describing what problem your coin solves and should be digestible to both tech and non-tech savvy audiences. You need to decide whether your coin offering will have a limited supply (think exclusivity) or if it can be minted in limitless amounts (which may/may not devalue your coin). Distribution method(s) and amounts should be well defined so everyone knows when and where the coins are going. When your ICO is ready, a good marketing or advertising campaign will really help your coin take off.