I'm trying to create an ERC20 token using truffle and upgradable openzeppelin contracts.
The problem is that the token balance is zero when I add the contract address into the Metamask extension.
When I use remix, Everything is Ok and I can see the correct balance of the deployed contract in the Metamask.
But I don't know where is the problem when I use it in localhost using Truffle
and Ganache
.
Token.sol:
pragma solidity ^0.8.2;
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20SnapshotUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
contract Token is
Initializable,
ERC20Upgradeable,
ERC20SnapshotUpgradeable,
OwnableUpgradeable,
PausableUpgradeable
{
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() initializer {}
function initialize() public initializer {
__ERC20_init("Token", "TKN");
__ERC20Snapshot_init();
__Ownable_init();
__Pausable_init();
_mint(msg.sender, 10000000000 * 18**decimals());
}
function snapshot() public onlyOwner {
_snapshot();
}
function pause() public onlyOwner {
_pause();
}
function unpause() public onlyOwner {
_unpause();
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
)
internal
override(ERC20Upgradeable, ERC20SnapshotUpgradeable)
whenNotPaused
{
super._beforeTokenTransfer(from, to, amount);
}
}
truffle-config.js:
networks: {
development: {
host: "localhost",
port: 7545,
network_id: "*",
},
// test: {
// host: "127.0.0.1",
// port: 7545,
// network_id: "*"
// }
},
Video: https://youtu.be/HHWsnlJxZ7Y