-
Notifications
You must be signed in to change notification settings - Fork 1
/
sneaker.sol
65 lines (45 loc) · 2.2 KB
/
sneaker.sol
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
61
62
63
64
65
// SPDX-License-Identifier: MIT;
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
contract Sneaker is ERC1155 {
using Counters for Counters.Counter;
Counters.Counter private _tokenId;
mapping(uint => string) private _tokenURIs;
constructor() ERC1155("ipfs://bafybeiglsd5it3st6h3znasju72rz7lndyz7325x2nez6g6jcvetsuvrom/") {}
function mint(address _recipient,uint _amount, string memory _tokenUrl) public returns(uint _mintTokenId){
require(bytes(_tokenUrl).length > 0,"The _tokenUrl must be have");
require(_amount > 0,"The _amount must be have");
_tokenId.increment();
uint newTokenId = _tokenId.current();
_mint(_recipient, newTokenId,_amount,"");
_tokenURIs[newTokenId] = _tokenUrl;
return newTokenId;
}
function mintBatch(address _recipient,uint[] memory _amounts,string[] memory _tokenUrls) public returns(uint[] memory _mintTokenIds){
require(_amounts.length > 0,"The _amounts must be have");
require(_tokenUrls.length > 0,"The _tokenUrls must be have");
require(_amounts.length == _tokenUrls.length,"The _tokenUrl length must be Equal _amounts length");
uint newTokenId;
uint[] memory returnTokenUrls = new uint[](_amounts.length);
for(uint256 i = 0; i < _amounts.length; i++){
_tokenId.increment();
newTokenId = _tokenId.current();
_tokenURIs[newTokenId] = _tokenUrls[i];
returnTokenUrls[i] = newTokenId;
}
_mintBatch(_recipient, returnTokenUrls,_amounts,"");
return returnTokenUrls;
}
function uri(uint256 _id) public view override returns(string memory _tokenUrl){
return _tokenURIs[_id];
}
function uriBatch(uint[] memory _tokenIds) public view returns(string[] memory _tokenUrls){
require(_tokenIds.length > 0,"The _tokenId must be have");
string[] memory returnTokenUrl = new string[](_tokenIds.length);
for(uint256 i=0;i<_tokenIds.length;i++){
returnTokenUrl[i] = _tokenURIs[_tokenIds[i]];
}
return returnTokenUrl;
}
}