Restore contract files

This commit is contained in:
Dario Gabriel Lipicar 2024-03-13 15:29:49 -03:00 committed by dlipicar
parent 29f221d30d
commit ccd764f995
2 changed files with 145 additions and 0 deletions

View File

@ -0,0 +1,88 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@openzeppelin/contracts@4.5.0/access/AccessControlEnumerable.sol";
import "@openzeppelin/contracts@4.5.0/token/ERC1155/extensions/ERC1155Supply.sol";
import "@openzeppelin/contracts@4.5.0/utils/Context.sol";
import "@openzeppelin/contracts@4.5.0/utils/Counters.sol";
contract Erc1155Faucet is Context, AccessControlEnumerable, ERC1155Supply {
string internal nftName;
string internal nftSymbol;
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
mapping(uint256 => string) internal _uriDict;
constructor() ERC1155("https://token-cdn-domain/{id}.json")
{
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
nftName = "ERC-1155 Faucet";
nftSymbol = "FA1155";
}
function mint(
address to,
uint256 amount,
string calldata tokenUri)
public
virtual
{
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_mint(to, tokenId, amount, "0x1234");
_uriDict[tokenId] = tokenUri;
}
function uri(uint256 id)
public
view
virtual
override
returns (string memory)
{
return _uriDict[id];
}
function name()
external
view
returns (string memory _name)
{
_name = nftName;
}
function symbol()
external
view
returns (string memory _symbol)
{
_symbol = nftSymbol;
}
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC1155, AccessControlEnumerable)
returns (bool)
{
return ERC1155.supportsInterface(interfaceId) || AccessControlEnumerable.supportsInterface(interfaceId);
}
function totalSupply()
public
view
returns (uint256)
{
uint256 result = 0;
uint256 maxId = _tokenIdCounter.current();
for(uint256 i = 0; i < maxId; i++)
{
result = result + totalSupply(i);
}
return result;
}
}

View File

@ -0,0 +1,57 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@openzeppelin/contracts@4.5.0/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts@4.5.0/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts@4.5.0/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts@4.5.0/access/Ownable.sol";
import "@openzeppelin/contracts@4.5.0/utils/Counters.sol";
contract Erc721Faucet is ERC721, ERC721Enumerable, ERC721URIStorage, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
constructor() ERC721("ERC-721 Faucet", "FA721") {}
function safeMint(address to, string memory uri)
public
{
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
_setTokenURI(tokenId, uri);
}
function _beforeTokenTransfer(address from, address to, uint256 tokenId)
internal
override(ERC721, ERC721Enumerable)
{
super._beforeTokenTransfer(from, to, tokenId);
}
function _burn(uint256 tokenId)
internal
override(ERC721, ERC721URIStorage)
{
super._burn(tokenId);
}
function tokenURI(uint256 tokenId)
public
view
override(ERC721, ERC721URIStorage)
returns (string memory)
{
return super.tokenURI(tokenId);
}
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721, ERC721Enumerable)
returns (bool)
{
return ERC721.supportsInterface(interfaceId) || ERC721Enumerable.supportsInterface(interfaceId);
}
}