Development Tool . Window Platform


Ethereum's DAPP development tool is not that friendly to beginner.


  • powershell
  • nodejs
  • npm
  • trufflesuite
  • ganache

Steps By Steps

  1. In browser, please navigate to https://nodejs.org/en/download/ and Click "Windows Installer" under LTS tab. Run installation once download complete, go page by page and eventually click finish to succeed the installation.
  2. Please be noted that nodejs installation come with npm.
  3. Run powershell as administrator and verify version of nodejs and npm.
    $ node –v
    # v12.18.4 in my version
    
    $ npm -v
    # 6.14.6 in my version
    		
  4. Install truffle.
    $ npm install -g truffle
    
    $ truffle version
    # Truffle v5.1.47 (core: 5.1.47)
    # Solidity v0.5.16 (solc-js)
    # Node v12.18.4
    # Web3.js v1.2.1
    		
  5. Next, install a private blockchain name ganache. In browser, please navigate to https://www.trufflesuite.com/ganache and click on "Download (WINDOWS)". Finish all the common installation steps.
  6. Ok, now create your project directory, with directory name is helloworld. In powershell
    # To create a bare Truffle project with no smart contracts included, use `truffle init`.
    $ truffle init
    
    # Once this operation is completed, you will see such project structure under your new created project directory.
        # contracts/: Directory for Solidity contracts
        # migrations/: Directory for scriptable deployment files
        # test/: Directory for test files for testing your application and contracts
        # truffle-config.js: Truffle configuration file
    		
  7. Create a truffle-config.js script and put content below.
    module.exports = {
    	networks: {
    		development: {
    			host: "127.0.0.1",
    			port: 7545,
    			network_id: "*" // Match any network id
    		}
    	}
    };
    		
  8. Open ganache program and click on new workspace, add project and select truffle-config.js you have created previously. Lastly, save this new workspace and you will a private blockchain is running.
  9. Now navigate to project directory/contracts. Create a new file Helloworld.sol and paste codings below inside it.
    pragma solidity >=0.4.22 <0.7.0;
    /**
     * @title Helloworld
     * @dev Store & retrieve value in a variable
     */
    contract Helloworld {
    
        uint256 number;
    
        /**
         * @dev Store value in variable
         * @param num value to store
         */
        function store(uint256 num) public {
            number = num;
        }
    
        /**
         * @dev Return value 
         * @return value of 'number'
         */
        function retrieve() public view returns (uint256){
            return number;
        }
    }
    		
  10. Create migration file
    #make sure you have CD to project directory
    
    $ truffle console 
    $ create migration helloworld_migration 
    
    #
    #open and paste the following migration script inside it
    
    		
  11. You will see a new file with name {timestamp}_helloworld_migration.js is created. Open and paste the following migration script inside it.
    let Helloworld = artifacts.require("./Helloworld.sol");  
      
    module.exports = function(deployer) {  
        deployer.deploy(Helloworld);  
    };
    		
  12. Now let's do migration to ganache. In powershell,
    #make sure you have CD to project directory
    $ Truffle Migrate 
    
    #You will see a success message showing total deployments: 1
    #In ganache, you will find out this new created contract under the "CONTRACTS" tab.
    		
  13. Now we are going to demostrate how to interact with this newly created contract.
    #make sure you have CD to project directory
    #enter console
    $ Truffle console 
    
    #declare a contract instance
    $ truffle(development)> let instance = await Helloworld.deployed()
    
    #store 123
    $ truffle(development)> instance.store(123)
    
    #retrieve 123
    $ truffle(development)> instance.retrieve()
    		








Tutorials
About Us
Contents have been open source in GITHUB. Please give me a ⭐ if you found this helpful :)
Community
Problem? Raise me a new issue.
Support Us
Buy me a coffee. so i can spend more nights for this :)

BTCSCHOOLS would like to present you with more pratical but little theory throughout our tutorials. Pages' content are constantly keep reviewed to avoid mistakes, but we cannot warrant correctness of all contents. While using this site, you agree to accept our terms of use, cookie & privacy policy. Copyright 2019 by BTCSCHOOLS. All Rights Reserved.