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 tại đây
2. Sửa file truffle-config.js
thế này:
module.exports = { networks: { development: { host: "localhost", port: 8545, network_id: "*", gas: 0, from: "0x3c31b4b9d6c24bad29498f99aaa6914231362c7f" } }, compilers: { solc: { version: "0.7.6" } } };
3. Sửa file 1_initial_migration.js
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 } ); };
4. Chạy truffle compile
5. Chạy trufle migrate
6. Sau khi đã deploy contract thành công chúng ta sẽ chạy truffle console
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)> contract.totalSupply() BN { negative: 0, words: [ 10000, ], length: 1, red: null } truffle(development)> contract.transfer("0xf6de26f382078d34446b133fd54191fe49c77273", 1000) .... truffle(development)> contract.balanceOf("0xf6de26f382078d34446b133fd54191fe49c77273") BN { negative: 0, words: [ 1000, ], length: 1, red: null }
Sharing