How to dynamically configure token name, symbol, and supply on deployment for ERC-20 and TRC-20 tokens
GeminiBenard
Sign in to confirm0 confirmations
Question
I need to create tokens on the Ethereum and Tron networks where the token name, symbol, and initial supply can be specified during deployment. How can I modify the standard ERC-20 and TRC-20 contract templates to achieve this?
Answer
To dynamically configure your tokens, you can modify the constructors of your ERC-20 and TRC-20 contracts to accept the token name, symbol, initial supply amount, and max supply cap as parameters. The provided contract examples demonstrate how to do this for both Ethereum and Tron networks.
solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/**
* ============================================================
* PenBreeze Token — ERC-20 (Ethereum / BSC / Polygon / etc.)
* ============================================================
*/
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
import "@openzeppelin/contracts/access/Ownable2Step.sol";
contract PenBreezeToken is
ERC20,
ERC20Burnable,
ERC20Capped,
ERC20Pausable,
ERC20Permit,
Ownable2Step
{
constructor(
string memory tokenName,
string memory tokenSymbol,
uint256 initialSupplyAmount,
uint256 maxSupplyCap,
address initialOwner
)
ERC20(tokenName, tokenSymbol)
ERC20Capped(maxSupplyCap * 10 ** 18)
ERC20Permit(tokenName)
Ownable(initialOwner)
{
require(initialSupplyAmount <= maxSupplyCap, "Initial supply exceeds cap");
_mint(initialOwner, initialSupplyAmount * 10 ** 18);
}
// ...
}solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* ============================================================
* PenBreeze Token — TRC-20 (Tron Network)
* ============================================================
*/
contract PenBreezeTokenTRC20 {
// ...
constructor(
string memory tokenName,
string memory tokenSymbol,
uint256 initialSupplyAmount,
uint256 maxSupplyCap
) {
require(initialSupplyAmount <= maxSupplyCap, "TRC20: initial supply exceeds cap");
name = tokenName;
symbol = tokenSymbol;
maxSupply = maxSupplyCap * 10 ** uint256(decimals);
owner = msg.sender;
uint256 initialSupply = initialSupplyAmount * 10 ** uint256(decimals);
totalSupply = initialSupply;
_balances[msg.sender] = initialSupply;
emit Transfer(address(0), msg.sender, initialSupply);
emit OwnershipTransferred(address(0), msg.sender);
}
// ...
}solidityethereumtronerc20trc20