February 20, 2019

How to become a Blockchain developer?

Blockchain and Smart Contract Development

Blockchain is a digitized, decentralized, public ledger of all cryptocurrency transactions. Each node in the blockchain has an exact copy of the whole blockchain.

What a Blockchain developer should know?

  1. You have to have little knowledge on economics and have general idea about transactions.
  2. You should also have basics of cryptography and how it works .
  3. Know about Bitcoin, Ethereum
  4. Know how cryptography is used in cryptocurrency
  5. Understand what Smart Contracts are
  6. Get to know tools for blockchain development
  7. Smart contract development with Ethereum

Links:

Terms:

  • Address — Address are alpha numeric hashes that are used to send or receive transactions on the network.
  • Block — they are the batches of the valid transactions that happend in the network
  • Blockchain — It is a shared ledger where transactions are permanently recorded as a sequence of blocks. It contains every transactions that the network performed to validate in a long chain of blocks, so called Blockchain.
  • Block Height — The length of the blockchain or the number of blocks in the blockchain
  • Mining — act of validating blockchain transactions
  • Block Reward — The reward given to the miner who participated in the network to validate the transactions.
  • Consensus — A general agreement between the nodes or particpants in the network for the validity of the transactions, ensuring the ledgers in all the nodes are exact copy of each other.
  • Dapp — An application running on a decentralized peer-to-peer network, that operates autonomously,stores the data in the blockchain and operates on a protocol that shows proof of value.
  • DAO — Decentralized Autonomous Organizations is a form of digital organization that runs without human intervention and controlled on the business rules .
  • Distributed Network — A network where each participating nodes work together to perform tasks.
  • Difficulty — It refers to how easily a data block of transaction can be mined
  • Double Spending — a potential flaw in digital cash scheme, where a single/same digital token can be spend more than once.
  • Genesis Block — The first block in the blockchain
  • Proof of Work — the proof of how much work you have done for validating transactions in the network
  • Smart Contracts — these are the business rules encoded into the blockchain that are executed by the participants in the network
  • Wallet — A file including private keys that allows access to the blockchain that the wallet is designed

Links:

Cryptocurrency

Cryptocurrency is a medium of exchange, created and stored electronically in the blockchain, using encryption techniques to control the creation of monetary units and to verify the transfer of funds.

Links:

What is a Blockchain Developers?

Software developers that figure out how to secure an immutable distributed database.

Smart Contracts?

Smart Contracts are decentralized application or programs that run on ethereum network. They are self executing contracts with the terms of the agreement between buyer and seller being directly written into lines of code.

Tools used for Blockchain / Smart contract Development

Create a basic smart contract in Ethereum

You will start by installing required tools required for development.

You need nodejs in your system to begin with,

$ sudo apt-get update
$ sudo apt-get install nodejs
$ sudo apt-get install npm

Now we will install truffle framework that interacts with ethereum blockchain

$ sudo npm install -g truffle 
$ truffle init

This will generate following files in the directory.

Edit truffle.js file that contains the configuration of the blockchain network.

module.exports = {
networks: {
development: {
host: "127.0.0.1", // ip where ganache is running blockchain server
port: 7545, // port in ganache
network_id: "*" // Match any network id
}
}
};

Create file Counter.sol in contracts directory

pragma solidity ^0.4.0;
contract Counter {
int private count = 0;
    function incrementCounter() public {
count += 1;
}
    function decrementCounter() public {
count -= 1;
}
    function getCount() public constant returns(int) {
return count;
}
}

Create another file 2_deploy_contracts.js in migrations directory

const Counter = artifacts.require("./Counter.sol")
module.exports = function(deployer) {
deployer.deploy(Counter);
};

Now, in the parent directory

 $ truffle compile

If the codes are all fine we will see no any issue.

$ truffle migrate --network development

What this does is upload the contract/s to the ethereum network through the rpc 127.0.0.1:7545

Using network ‘development’.
Running migration: 1_initial_migration.js
Deploying Migrations…
… 0xecfe9a07b6f4df2afa0b07d3be9e9302f13c8493c1cb5a5c5c3e4a4c2480e50d
Migrations: 0x8cdaf0cd259887258bc13a92c0a6da92698644c0
Saving successful migration to network…
… 0xd7bc86d31bee32fa3988f1c1eabce403a1b5d570340a3a9cdba53a472ee8c956
Saving artifacts…
Running migration: 2_deploy_contracts.js
Deploying Counter…
… 0x8bf41f7687ae0ef27a7fa9457fd98137336259f09d4d4dac8d2ae21649fbb3ae
Counter: 0x345ca3e014aaf5dca488057592ee47305d9b3e10
Saving successful migration to network…
… 0xf36163615f41ef7ed8f4a8f192149a0bf633fe1a2398ce001bf44c43dc7bdda0
Saving artifacts…

Migrations is the default contract truffle init creates. The contract Counter we created will be deployed in network as we can see above at 0x345ca3e014aaf5dca488057592ee47305d9b3e10.

Once the contracts are uploaded to the ethereum network, we will see a contract address which is what used in the future for calling the methods in the contract.

From the above example we have successfully created a simple Counter contract. This contract we have methods to get counter (getCount), increment(incrementCounter)/decrement (decrementCounter) the counter in the contract.

Now we can directly access the method in the contract directly through the truffle console being inside the project directory.

$ truffle console

To get the accounts that are present in the network.

truffle(development)> addresses = web3.eth.accounts

To get first and seconds account in the network:

truffle(development)> address0 = web3.eth.accounts[0]
truffle(development)> address0 = web3.eth.accounts[1]

To get the address of the contract that was deployed in the network

truffle(development)> Counter.deployed().then(instance => console.log(instance.address))
0x345ca3e014aaf5dca488057592ee47305d9b3e10

Alternatively:

../counter-contract$ truffle networks

Network: UNKNOWN (id: 5777)
 Counter: 0x345ca3e014aaf5dca488057592ee47305d9b3e10
 Migrations: 0x8cdaf0cd259887258bc13a92c0a6da92698644c0

or

truffle(development)> counter = Counter.address

Call the method in the contract:

truffle(development)> Counter.at(“0x345ca3e014aaf5dca488057592ee47305d9b3e10”).getCount()

Alternatively:
truffle(development)> Counter.deployed().then(function(instance){app = instance})

truffle(development)> app. <tab>
 app.abi app.address app.allEvents
 app.contract app.decrementCounter app.getCount
 app.incrementCounter app.send app.sendTransaction
 app.transactionHash

truffle(development)> app.getCount()
 { [String: ‘0’] s: 1, e: 0, c: [ 0 ] }

The get methods in the contract all have no fees however, if the method/call changes the state of the values in the contract then is requires gas ie. money.

There is another way to interact the methods in the contract through GUI with MyEtherWallet. We will continue with interacting with Blockchain network in local through MyEtherWallet in later tutorial.

Attribution – This article is originally published on our Coinmonks publication by Sagar Duwal

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *