-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathERC20withMetadata.sol
More file actions
60 lines (48 loc) · 1.55 KB
/
ERC20withMetadata.sol
File metadata and controls
60 lines (48 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract ERC20withMetadata is ERC20 {
string private _image;
address private _creator;
string private _metadata;
uint8 private immutable _decimals = 18;
uint256 private _createdBlock;
modifier onlyCreator() internal {
require(msg.sender == _creator, "Only token creator is authorized");
_;
}
event MetadataUpdated(string newMetadata);
constructor(
address creator_,
uint256 initialSupply_,
string memory name_,
string memory symbol_,
string memory image_,
string memory metadata_
) ERC20(name_, symbol_) {
_createdBlock = block.number;
_creator = creator_;
_image = image_;
setMetadata(metadata_);
_mint(address(this), initialSupply_ * (10 ** _decimals));
}
function decimals() public pure override returns (uint8) {
return _decimals;
}
function image() external view virtual returns (string memory) {
return _image;
}
function creator() public view virtual returns (address) {
return _creator;
}
function createdBlock() external view virtual returns (uint256) {
return _createdBlock;
}
function metadata() external view virtual returns (string memory) {
return _metadata;
}
function setMetadata(string memory metadata_) public onlyCreator {
_metadata = metadata_;
emit MetadataUpdated(metadata_);
}
}