Skip to content
SirajChaudhary edited this page Mar 20, 2022 · 2 revisions

Step-by-step instructions to create bigcoin-cryptocurrency-dapp from scratch

Step1: Install Truffle framework and other dependencies

  • sudo npm install -g truffle
  • sudo npm install -g solc

Step2: Create truffle project (scaffold)

  • mkdir bigcoin-cryptocurrency-dapp
  • cd bigcoin-cryptocurrency-dapp
  • truffle init

Step3: Create a smart contract (scaffold)

  • truffle create contract BigCoin

-This is how initial solidity program look like,

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

contract BigCoin {
  constructor() {
  }
}

Step4: Create a test (scaffold)

  • truffle create test BigCoin

Step5: Add the file migrations/2_deploy_contract.js for deployment

var bigCoin = artifacts.require("./BigCoin.sol");
module.exports = function(deployer) {
   deployer.deploy(bigCoin);
};

Step6: Update the truffle task runner truffle-config.js

module.exports = {
  networks: {
    development: {
     host: '3.111.231.143',     // Private Blockchain Server (default: none)
     port: 8545,            // Standard Ethereum port (default: none)
     network_id: 2022       // Private Blockchain Network ID (default: none)
    },
  },

  // Set default mocha options here, use special reporters etc.
  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.8.11",    
    }
  },
};

Step7: Compile smart contracts

  • truffle compile

-Run the tests of smart contracts

  • truffle test

Step8: Deploy smart contracts

  • truffle migrate To deploy into specific network as per truffle-config.js file fire truffle migrate --network development

-To redeploy the contract

  • truffle migrate --reset

Step9: Create package.json (ExpressJS App) and add openzeppelin library and other dependencies

  • npm init
  • npm install @openzeppelin/contracts --save
  • npm install nodemon --save
  • npm install express --save
  • npm install jquery --save
  • npm install body-parser --save
  • npm install @babel/core @babel/cli babel-eslint babel-loader babel-plugin-transform-runtime babel-preset-env babel-preset-es2015 babel-register --save-dev
  • npm install css-loader --save-dev
  • npm install json-loader --save-dev
  • npm install style-loader --save-dev
  • npm install @truffle/contract --save-dev
  • npm install web3 --save-dev

Step10: Update the BigCoin.sol then compile and redeploy

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

import "./../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract BigCoin is ERC20 {
    constructor(uint256 initialSupply) ERC20("BigCoin", "BC") {
        _mint(msg.sender, initialSupply);
    }
}

Step11: Update the file migrations/2_deploy_contract.js

var bigCoin = artifacts.require("./BigCoin.sol");
module.exports = function(deployer) {
   deployer.deploy(bigCoin, 200000);
};

Step12: Compile & Redeploy the smart contracts

  • truffle compile
  • truffle migrate --reset

Step13: Create "/app" folder having all REST endpoints for smart contracts & also having frontend public-static-resources (css/js/images...). Please check the code

Technology stack used

TECHNOLOGY VERSION
Geth 1.10.16-stable
Truffle 4.5.1
Web3 1.7.1
Solidity Compiler 0.8.11
Smart Contract ERC20 -
OpenZeppelin 4.5.0
Go 1.17.6
NodeJS v10.19.0
ExpressJS 4.17.3
JQuery, Nodemon Latest
css-loader, json-loader, style-loader Latest
VSCode Studio Latest
Shell Script (Bash), Git Latest
VMs (Linux), Security Group, Firewall -
Postman Latest

How to start the DApp

  • 1) npm install
  • 2) npm start
  • 3) visit http://localhost:3000/