- Tải ERC20 contract tại đây
- Sửa file
truffle-config.jsthế 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
1_initial_migration.jsthế 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
truffle consolevà 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
}