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:
- Tải ERC20 contract <a href="https://github.com/ethereum-optimism/Truffle-ERC20-Example/tree/master/contracts" target="_blank">tại đây</a>
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"
}
}
};
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 }
);
};
- Chạy truffle compile
- Chạy trufle migrate
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)> 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
}