Avatar
0
monkey Enlightened
monkey Enlightened
Deploy ERC20 (smart contract cho ICO) lên mạng private
Dể deploy ERC20 (smart contract cho ICO) lên mạng private, chúng ta cần trải qua các bước sau:
  1. Tải ERC20 contract <a href="https://github.com/ethereum-optimism/Truffle-ERC20-Example/tree/master/contracts" target="_blank">tại đây</a>
  2. Sửa file <code>truffle-config.js</code> thế này:
    module.exports = {
        networks: {
            development: {
                host: "localhost",
                port: 8545,
                network_id: "*",
                gas: 0,
                from: "0x3c31b4b9d6c24bad29498f99aaa6914231362c7f"
            }
        },
        compilers: {
            solc: {
                version: "0.7.6" 
            }
        }
    };
    
  1. Sửa file <code>1_initial_migration.js</code> thế này:
    const ERC20 = artifacts.require("ERC20");
    
    module.exports = function (deployer) {
        const tokenName = 'My First Coin';
        const tokenSymbol = 'MFC';
        const tokenDecimals = 1;
        
        deployer.deploy(
            ERC20, 
            10000, 
            tokenName, 
            tokenDecimals, 
            tokenSymbol,
            { gasPrice: 0 }
        );
    };
    
  1. Chạy truffle compile
  2. Chạy trufle migrate
  3. Sau khi đã deploy contract thành công chúng ta sẽ chạy <code>truffle console</code> và gọi thử các lệnh:
    let contract = await ERC20.deployed()
    contract.totalSupply()
    contract.transfer("0xf6de26f382078d34446b133fd54191fe49c77273", 1000)
    contract.balanceOf("0xf6de26f382078d34446b133fd54191fe49c77273")
    
Kết quả chúng ta sẽ nhận được:
truffle(development)&gt; contract.totalSupply()
BN {
  negative: 0,
  words: [ 10000,  ],
  length: 1,
  red: null
}
truffle(development)&gt; contract.transfer("0xf6de26f382078d34446b133fd54191fe49c77273", 1000)
....
truffle(development)&gt; contract.balanceOf("0xf6de26f382078d34446b133fd54191fe49c77273")
BN {
  negative: 0,
  words: [ 1000,  ],
  length: 1,
  red: null
}
  • 1 Answer(s)
  • 1701 Views
  • Answer
blockchain ethereum erc20
Remain: 5
1 Answer
Avatar
monkey Enlightened
monkey Enlightened
Sharing
  • 0
  • Reply
0%

Media

Add New Media

Media Details

Uploaded On
File Name
File Type
File Size
Dimension