├── NFT.sol └── token.sol /NFT.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.3; 3 | 4 | import "@openzeppelin/contracts/utils/Counters.sol"; 5 | import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; 6 | import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; 7 | 8 | contract PixlNFT is ERC721URIStorage { 9 | 10 | using Counters for Counters.Counter; 11 | Counters.Counter private _tokenIds; 12 | 13 | constructor() ERC721("ExampleNFT", "ENFT") { 14 | } 15 | 16 | function createToken(string memory tokenURI) public payable returns (uint) { 17 | require(msg.value >= 1000000000000000000, "Not enough EHT sent; check price!"); 18 | _tokenIds.increment(); 19 | uint256 newItemId = _tokenIds.current(); 20 | 21 | _mint(msg.sender, newItemId); 22 | _setTokenURI(newItemId, tokenURI); 23 | 24 | return newItemId; 25 | } 26 | } -------------------------------------------------------------------------------- /token.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | pragma solidity 0.8.12; 3 | 4 | 5 | interface IERC20 { 6 | 7 | function totalSupply() external view returns (uint256); 8 | function balanceOf(address account) external view returns (uint256); 9 | function transfer(address recipient, uint256 amount) external returns (bool); 10 | function allowance(address owner, address spender) external view returns (uint256); 11 | function approve(address spender, uint256 amount) external returns (bool); 12 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); 13 | event Transfer(address indexed from, address indexed to, uint256 value); 14 | event Burn(address indexed from, uint256 value); 15 | event Approval(address indexed owner, address indexed spender, uint256 value); 16 | } 17 | 18 | 19 | pragma solidity 0.8.12; 20 | 21 | 22 | interface IERC20Metadata is IERC20 { 23 | function name() external view returns (string memory); 24 | function symbol() external view returns (string memory); 25 | function decimals() external view returns (uint256); 26 | } 27 | 28 | pragma solidity 0.8.12; 29 | 30 | abstract contract Context { 31 | function _msgSender() internal view virtual returns (address) { 32 | return msg.sender; 33 | } 34 | 35 | function _msgData() internal view virtual returns (bytes calldata) { 36 | this; // silence state mutability warning without generating bytecode 37 | return msg.data; 38 | } 39 | } 40 | 41 | pragma solidity 0.8.12; 42 | 43 | 44 | contract ERC20 is Context, IERC20, IERC20Metadata { 45 | mapping (address => uint256) private _balances; 46 | mapping (address => mapping (address => uint256)) private _allowances; 47 | uint256 private _totalSupply; 48 | uint256 private _decimals; 49 | string private _name; 50 | string private _symbol; 51 | address private _owner; 52 | 53 | 54 | 55 | constructor (string memory name_, string memory symbol_,uint256 initialBalance_,uint256 decimals_) { 56 | _name = name_; 57 | _symbol = symbol_; 58 | _totalSupply = initialBalance_* 10**decimals_; 59 | _balances[msg.sender] = _totalSupply; 60 | _decimals = decimals_; 61 | _owner = msg.sender; 62 | emit Transfer(address(0), msg.sender, _totalSupply); 63 | } 64 | 65 | function name() public view virtual override returns (string memory) { 66 | return _name; 67 | } 68 | 69 | function symbol() public view virtual override returns (string memory) { 70 | return _symbol; 71 | } 72 | 73 | function decimals() public view virtual override returns (uint256) { 74 | return _decimals; 75 | } 76 | 77 | function totalSupply() public view virtual override returns (uint256) { 78 | return _totalSupply; 79 | } 80 | 81 | function balanceOf(address account) public view virtual override returns (uint256) { 82 | return _balances[account]; 83 | } 84 | 85 | function transfer(address recipient, uint256 amount) public virtual override returns (bool) { 86 | _transfer(_msgSender(), recipient, amount); 87 | return true; 88 | } 89 | 90 | function allowance(address owner, address spender) public view virtual override returns (uint256) { 91 | return _allowances[owner][spender]; 92 | } 93 | 94 | function approve(address spender, uint256 amount) public virtual override returns (bool) { 95 | _approve(_msgSender(), spender, amount); 96 | return true; 97 | } 98 | 99 | function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { 100 | _transfer(sender, recipient, amount); 101 | 102 | uint256 currentAllowance = _allowances[sender][_msgSender()]; 103 | require(currentAllowance >= amount, "Transfer amount exceeds allowance"); 104 | _approve(sender, _msgSender(), currentAllowance - amount); 105 | 106 | return true; 107 | } 108 | 109 | function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { 110 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); 111 | return true; 112 | } 113 | 114 | 115 | function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { 116 | uint256 currentAllowance = _allowances[_msgSender()][spender]; 117 | require(currentAllowance >= subtractedValue, "Decreased allowance below zero"); 118 | _approve(_msgSender(), spender, currentAllowance - subtractedValue); 119 | 120 | return true; 121 | } 122 | 123 | 124 | function _transfer(address sender, address recipient, uint256 amount) internal virtual { 125 | require(sender != address(0), "Transfer from the zero address"); 126 | require(recipient != address(0), "Transfer to the zero address"); 127 | 128 | uint256 senderBalance = _balances[sender]; 129 | require(senderBalance >= amount, "Transfer amount exceeds balance"); 130 | 131 | _balances[sender] = senderBalance - amount; 132 | _balances[recipient] += amount; 133 | 134 | emit Transfer(sender, recipient, amount); 135 | } 136 | 137 | function _approve(address owner, address spender, uint256 amount) internal virtual { 138 | require(owner != address(0), "Approve from the zero address"); 139 | require(spender != address(0), "Approve to the zero address"); 140 | _allowances[owner][spender] = amount; 141 | emit Approval(owner, spender, amount); 142 | } 143 | 144 | /*function mint(uint256 amount) public returns(bool) { 145 | require(msg.sender == _owner, "Only the owner can mint new tokens"); 146 | _totalSupply += amount; 147 | _balances[_owner] += amount; 148 | emit Transfer(address(0), _owner, amount); 149 | return true; 150 | } 151 | 152 | function burn(uint256 amount) public returns(bool) { 153 | require(_balances[msg.sender] >= amount, "Amount exceeded"); 154 | _totalSupply -= amount; 155 | _balances[msg.sender] -= amount; 156 | emit Burn(msg.sender, amount); 157 | return true; 158 | }*/ 159 | } 160 | 161 | pragma solidity ^0.8.0; 162 | 163 | 164 | contract MyToken is ERC20 { 165 | constructor( 166 | string memory name_, 167 | string memory symbol_, 168 | uint256 decimals_, 169 | uint256 initialBalance_, 170 | address payable feeReceiver_ 171 | ) payable ERC20(name_, symbol_,initialBalance_,decimals_) { 172 | payable(feeReceiver_).transfer(msg.value); 173 | } 174 | } --------------------------------------------------------------------------------