Sample smart contract to create your own token:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.0.0/contracts/token/ERC20/ERC20.sol";
contract Token is ERC20 {
constructor(string memory name, string memory symbol, uint256 initialSupply) ERC20(name, symbol) {
_mint(msg.sender, initialSupply * 10**uint(decimals()));
}
}
The same code, but with a hard-coded name, symbol and initial supply:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.0.0/contracts/token/ERC20/ERC20.sol";
contract Token is ERC20 {
constructor() ERC20("TestTokenName", "TEST") {
_mint(msg.sender, 2000 * 10**uint(decimals())); // mint 2000 tokens
}
}
Sources:
https://docs.openzeppelin.com/contracts/4.x/erc20
https://solidity-by-example.org/app/erc20/
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.0.0/contracts/token/ERC20/ERC20.sol