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: <p> </p> <ol start="1"> <li>Tải ERC20 contract <a href="https://github.com/ethereum-optimism/Truffle-ERC20-Example/tree/master/contracts" target="_blank">tại đây</a> </li> </ol> <p> </p> <ol start="2"> <li>Sửa file <code>truffle-config.js</code> thế này: </li> </ol> <p> </p> <pre> module.exports = { networks: { development: { host: "localhost", port: 8545, network_id: "*", gas: 0, from: "0x3c31b4b9d6c24bad29498f99aaa6914231362c7f" } }, compilers: { solc: { version: "0.7.6" } } }; </pre> <p> </p> <ol start="3"> <li>Sửa file <code>1_initial_migration.js</code> thế này: </li> </ol> <p> </p> <pre> 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 } ); }; </pre> <p> </p> <ol start="4"> <li>Chạy truffle compile </li> <li>Chạy trufle migrate </li> </ol> <p> </p> <ol start="6"> <li>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: </li> </ol> <p> </p> <pre> let contract = await ERC20.deployed() contract.totalSupply() contract.transfer("0xf6de26f382078d34446b133fd54191fe49c77273", 1000) contract.balanceOf("0xf6de26f382078d34446b133fd54191fe49c77273") </pre> <p> </p> <p> Kết quả chúng ta sẽ nhận được: </p> <p> </p> <pre> 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 } </pre>
Answer