Creating a New PrivateERC20 Token
PrivateERC20 is an abstract contract. To create a new token, extend it and call the constructor with a name and symbol.
Minimal Token
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "../PrivateERC20.sol";
contract MyPrivateToken is PrivateERC20 {
constructor() PrivateERC20("My Private Token", "p.MYT") {}
}That's it. The deployer automatically receives DEFAULT_ADMIN_ROLE and publicAmountsEnabled is set to true.
Custom Decimals
Override decimals() to change from the default 18:
contract PrivateTetherUSD is PrivateERC20 {
constructor() PrivateERC20("Private Tether USD", "p.USDT") {}
function decimals() public view virtual override returns (uint8) {
return 6;
}
}Role-Based Access
PrivateERC20 uses OpenZeppelin AccessControl:
Role
Constant
Purpose
DEFAULT_ADMIN_ROLE
0x00
Granted to deployer; can grant/revoke roles, toggle publicAmountsEnabled
MINTER_ROLE
keccak256("MINTER_ROLE")
Required to call mint()
Grant MINTER_ROLE to contract administrator
Deploying with Hardhat
Last updated
Was this helpful?