Nickelback Plays Music

    @pigzbe/erc20-contract

    3.3.2 • Public • Published

    Pigzbe ERC20 Burnable Contract

    This contract is based on OpenZeppelin.org Burnable Token

    https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/token/ERC20/BurnableToken.sol

    This tool is intended to be used in any Pigzbe/Wollo project that requires access to the ERC20 Token, so all applications have the same code.

    Install on your project

    yarn add @pigzbe/erc20-contract

    .env.json file

    Run on your project folder

    pigzbe-contract init
    

    this will create a .env.json file in for you or create an .env.json file in manually with the following

    You only need the local network parameters, the tool will output a JSON file with the deployed networks automatically.

    {
      "CONTRACT_VARS_PATH": "./erc20-contract.json",
      "networks" : {
        "local" : {
          "KEY_MNEMONIC": "",
          "SEED_INDEX": 0,
          "RPC_HOST": "http://127.0.0.1:7545"
        }
      }
    }
    

    Vars description:

    • CONTRACT_VARS_PATH is where the Contract variables will be output
    • CONTRACT_SOL_DIR is where the flattened sol contracts will be output
    • KEY_MNEMONIC Is the Ethereum account memorable works (seed)
    • SEED_INDEX Index account the tool should derive the seed in order to get the private key of the account
    • PRIVATE_KEY is the ethereum private key account to deploy the contract from

    Use either KEY_MNEMONIC + SEED_INDEX combination or PRIVATE_KEY to deploy your contracts to the networks

    To deploy the contract locally run

    if you have exported the local node_modules folder on your bash profile

    export PATH="./node_modules/.bin/:$PATH"

    You can run the following commands without prefixing it with ./node_modules/.bin

    # looks for the default .env.json file in the project root and deploy on default local network
    pigzbe-contract deploy
    
    # looks for the default .env.json file in the project root and on all networks listed on .env.json, otherwise only compile/deploy to local network
    
    # BE EXTRA CAREFUL WHEN USING THE FOLLOWING FLAGS, ALL PROJECTS SHOULD BE UPDATED TO GET THE NEW CONTRACTS
    
    # Compiles and deploys new contracts
    pigzbe-contract deploy
    
    # Compiles contracts without deploying to any networks
    pigzbe-contract deploy --dryrun
    
    # if you want to pass a different path for your .env.json file
    pigzbe-contract deploy --env .env.json
    
    # you can check the help by running
    pigzbe-contract --help
    
    # or a help for the deploy function  by running
    pigzbe-contract deploy --help
    

    This will take the .env.json file, create the wallet to deploy the contract to the network, merge the contract with the latest OpenZeppelin dependencies, create the ABI and Binary of the contract, deploy on local network and create a JSON file in the path set on CONTRACT_VARS_PATH in the .env.json with the following

    {
      "TokenName": {
        "abi": [],
        "networks": {
          "local": {
            "network": "local",
            "rpc": "Network RPC",
            "name": "Contract Name",
            "address": "Address the contract is deployed to"
          },
          [...]
        }
      }
    }
    

    With those parameters, you can use web3 to create and interact with your contract like

    const Web3 = require('web3')
    const ercContract = require('../erc20-contract.json')
    
    const getContract = async () => {
      const contract = ercContract.local
      // your local geth server RPC http url
      const URL_PROVIDER = contract.rpc
      const web3 = new Web3(new Web3.providers.HttpProvider(URL_PROVIDER))
    
      try {
        const deployedContract = new web3.eth.Contract(contract.abi, contract.address, {
          gasPrice: await web3.eth.getGasPrice(),
          gas: 6721975
        })
    
        console.log(deployedContract)
      } catch (e) {
        console.log(e)
      }
    }
    
    getContract()

    Keywords

    none

    Install

    npm i @pigzbe/erc20-contract

    DownloadsWeekly Downloads

    27

    Version

    3.3.2

    License

    MIT

    Unpacked Size

    203 kB

    Total Files

    32

    Last publish

    Collaborators

    • ianmcgregor
    • silviopaganini