How to run your ethereum based smart contracts using a private blockchain server (localhost): PRACTICAL

Shubham Kumar Gupta
3 min readFeb 21, 2021

--

Blockchain: I am simple terms, it is a collection/chains of blocks containing data.

Let’s understand it with an example of trains.

Every coach contains information, materials to carry, etc.

Now every coach has its unique number.

This you can take as the hash key of this coach.

Now, this coach is connected with different other coaches.

Now imagine if, at the joints, it is written that coach ABC is connected to coach XYZ where ABC and XYZ are coach numbers of trains.

Here every coach is first validated, tested, then attached to a train.

This is how actually a blockchain system works.

Every block contains data, its hash key, and a previous hash key.

Now, as you know, in every coach, many persons have different tasks. Similarly, a single block in the blockchain has multiple transactions, each with a hash key; the idea/technique to get the final and a single hash key for the block is called MERKLE TREE.

Below shows you how the hash code is calculated for a single block.

Now, Let’s create our project.

Steps:

Metamask Extension

  • Install Metamask Extension in your browser
  • Login/Register
  • Switch to Test Network
  • Ask for free Test ethers using the deposit section (create a post with your Twitter and copy URL to get test ethers)

Remix Ethereum

  • open Remix ethereum website(https://remix.ethereum.org/)
  • delete all and create a new file named Bank.sol ( copy my code :D )
  • now click deploy using Injected web3 option in the run section
  • You can test your code is working or not using compile and run section in the remix
  • You can check your contract address in deployed contracts option

Website localhost

  • open using vs. code
  • Run below two lines in terminal ( NODEJS NPM :) )

npm install -g http-server

http-server

  • Now replace your contract address in the address variable.
  • RUN CODE

--

--

Shubham Kumar Gupta
Shubham Kumar Gupta

No responses yet