Smart Contract and Web3! All that you need to know.
Tags: Blockchain Technology, Solidity, Web3, Chainide

Smart Contract and Web3! All that you need to know. Ali Follow Jul 23 · 5 min read

A Glorious guide on creating your smart contracts and interact with smart contracts using web3

1. A system to store data on the blockchain and retrieve the stored data from the blockchain

Pre-requisite:

To follow this tutorial, you need to have a basic knowledge of the following programming languages:

HTML: HTML is used to design the structure of the website JavaScript: Javascript is used for interacting with the deployed smart contracts to store, retrieve, and manipulate information Solidity: solidity is used for writing down smart contracts

Tools Requirement:

ChainIDE [an online cloud-based, multi-chain IDE] available at: https://chainide.com/

MetaMask [a wallet for web3], available at: https://metamask.io/

!Note: For this tutorial, you don’t need to download any tools or libraries except MetaMask and web3.js.

Libraries:

web3.js [web3.js is a collection of libraries that allow you to interact with a local or remote ethereum node using HTTP, IPC, or WebSocket], available at: https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/web3.min.js

Experiment Setup:

Once you have access to ChainIDE and MetaMask, connect MetaMask to ChainIDE and buy some ethers from a faucet for any of the following test networks:

Ropsten Test Network (suggested) Kovan Test Network Rinkbey Test Network Goreli Test Network

To get test ethers from a faucet, simply click choose any of the above-mentioned networks and click on Buy →Test Faucet → Get Ether, and you will be redirected to the selected faucet network. This method varies a little from network to network but all are quite easy.

2. MetaMask

After adding the extension of MetaMask to your browser, make sure you have selected the faucet network.

Method

First of all, we will write down a smart contract that can store the employee's information such as id, first name, last name, address, mobile number, etc.,

!Note: We’ll use ChainIDE for the whole tutorial, ChainIDE supports all the programming languages that are needed to complete this tutorial.

Following code is a smart contract written in solidity that is used to store the employee's information on the blockchain. To make use of this smart contract, we need to deploy it on the blockchain, and before, we can deploy it, we need to compile it.

The pragma keyword defines the compiler version that we will use to compile the solidity code. Once you have completed writing down your smart contract, simply compile it from the compile panel, and you will get the ABI code for the following solidity code.

3. Contract Compilation

The ABI which is known as the application binary interface is needed when you want to interact with the smart contract using web3.

Now, the next step is to deploy the complied smart contract.

4. Contract Deployment

To deploy a smart contract, you must need to have some faucet ethers in your wallets to pay a gas fee to deploy for the smart contract. In fig.4, we can see we paid 25 gwei to deploy our “Employee_Records.sol” smart contract.

Once a smart contract is deployed, it will be assigned a contract address, as we can see in fig.4, highlighted pint 3, and from the interaction panel, we can copy our smart contract address and can check our deployed smart contract on the faucet network also.