Code Monkey home page Code Monkey logo

deployer-hardhat's Introduction

Initial Coin Offering (ICO) contract

Tutorial using Hardhat(Buidler) to complie, deploy and automated unit tests Solidity smart contract.
you use this repository as Initial Coin Offering (ICO) contract template or ERC20 template.
To run these tutorials, you must have the following installed:

$ npm install

to compile your smart contract to get an ABI and artifact of a smart contract.

$ npm run compile

for a unit testing smart contract using the command line.

$ npm run test

expecting sample-test.js result.

  Initial Coin Offering (ICO) contract
    ✓ Assigns initial balance (97ms)
    ✓ Do not have permission to minting token (95ms)
    ✓ Do not have permission to burning token (74ms)
    ✓ Buy token with ether (212ms)
    ✓ Do not have permission to withdraw ether from contract (69ms)
    ✓ Transfer adds amount to destination account (99ms)
    ✓ Transfer emits event (132ms)
    ✓ Can not transfer above the amount (63ms)
    ✓ Can not transfer from empty account (77ms)
    ✓ Minting token (100ms)
    ✓ Burning token (73ms)
    ✓ Withdraw ether from contract (61ms)
    ✓ Do not have enough ether to buy token (30ms)


  13 passing (2s)

after testing if you want to deploy the contract using the command line.

$ npm run test-rpc
# Open another Terminal
$ npm run deploy-local

# result in npx hardhat node Terminal
web3_clientVersion
eth_chainId
eth_accounts
eth_chainId
eth_estimateGas
eth_gasPrice
eth_sendTransaction
  Contract deployment: <UnrecognizedContract>
  Contract address:    0x5fb...aa3
  Transaction:         0x4d8...945
  From:                0xf39...266
  Value:               0 ETH
  Gas used:            323170 of 323170
  Block #1:            0xee6...85d

eth_chainId
eth_getTransactionByHash
eth_blockNumber
eth_chainId (2)
eth_getTransactionReceipt

# result in npx hardhat run Terminal
Initial Coin Offering (ICO) contract deployed to: 0x5Fb...aa3

your can edit deploy network endpoint at hardhat.config.js.

module.exports = {
  networks: {
        {
        localhost: {
          url: "http://127.0.0.1:8545"
        },
        hardhat: {
          // See its defaults
        }
  }
};

Example customized function
If you want to pay token fee to the miner or validator in the network.

    // pragma solidity 0.8.0
    // Solidity 0.8.X has an integrated SafeMath Library
    // override function transfer to distribute fee to miner or validator in the network
    /* Diagram transfer with token fees
      ##### Before #####
      A balance: 101
      B balance: 0
      C balance: 0

      A.transfer(B.address,101);
                    A
                    |	
                    | transfer Tx
                    |_____ 
                    |     |
                    v     v				
                    B     C

      ##### After #####
      A balance: 0
      B balance: 100
      C balance: 1
    */
    function transfer(address account,uint256 amount) public override returns(bool){
        require(amount % 10 != 0, "ERC20: insufficient funds");
        uint256 fee = amount % 10;
        _transfer(msg.sender,account,amount-fee);
        _transfer(msg.sender,block.coinbase,fee);
        return true;
    }

deployer-hardhat's People

Contributors

masdxi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.