Getting Started with Ethereum Blockchain Development
this tutorial will show how to develop your own Blockchain environment with Ethereum by writing, deploy and test your first smart contract π
steps:
1. Installation (donβt forget to create a directory before doing installations. in my case it is blockchain-project-cg)
– Node Environment. Download node.js installer here
– Solc Compiler. npm install -g solc
– Go Ethereum. Download here
– Truffle Framework. npm install -g truffle
– Ganache. npm install -g ganache-cli
2. Writing Smart Contract
– truffle-config.js (add this to)
module.exports = {
networks: {
development: {
host: “127.0.0.1”,
port: 8545,
network_id: “*” // Match any network id
}
}
};
– /contracts/counter.sol
pragma solidity ^0.5.12;
contract Counter {
event CounterIncrementedEvent(int count);
event CounterDecrementedEvent(int count);
int private count = 0;
function incrementCounter() public {
count += 1;
emit CounterIncrementedEvent(count);
}
function decrementCounter() public {
count -= 1;
emit CounterDecrementedEvent(count);
}
function getCount() public constant returns (int) {
return count;
}
}
– /migrations/2_initial_migration.js
var Counter = artifacts.require(“./Counter.sol”);
module.exports = function(deployer) {
deployer.deploy(Counter);
};
3. /test/counter_test.js
const Counter = artifacts.require(“Counter”);
contract(‘Counter test’, async (accounts) =(angle bracket) {
let instance;
before(async () =(angle bracket) {
instance = await Counter.deployed();//deploy contract
});
it(“Initial value of counter should be zero”, async () =(angle bracket) {
let count = await instance.getCount.call({from: accounts[0]});
assert.equal(count, 0);
});
});
4. ganache-cli
5. truffle test
6. You can see the result of the counter Contracts π and you have successfully deployed and tested your first smart contract π notice the change of block number, gas usage, etc π in the next tutorial we will learn to do voting with blockchain π
IMPORTANT NOTES: please check the listing of codes in the video because it is not allowed to put angle brackets in the description
References:
thanks for watching, donβt forget to subscribe, activate the notification bell, like this video and also share it to support this channel to be able to continuously creates useful tutorials π
leave us some comments if there is any questions and let us know what you think π
also visit our website:
and blog:
and follow us on Instagram:
Twitter:
Facebook: