-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathNFTCreator.sol
73 lines (56 loc) · 2.19 KB
/
NFTCreator.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
66
67
68
69
70
71
72
73
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.9.0;
import './HederaResponseCodes.sol';
import './IHederaTokenService.sol';
import './HederaTokenService.sol';
import './ExpiryHelper.sol';
contract NFTCreator is ExpiryHelper {
function createNft(
string memory name,
string memory symbol,
string memory memo,
int64 maxSupply,
uint32 autoRenewPeriod
) external payable returns (address){
IHederaTokenService.TokenKey[] memory keys = new IHederaTokenService.TokenKey[](1);
// Set this contract as supply
keys[0] = getSingleKey(KeyType.SUPPLY, KeyValueType.CONTRACT_ID, address(this));
IHederaTokenService.HederaToken memory token;
token.name = name;
token.symbol = symbol;
token.memo = memo;
token.treasury = address(this);
token.tokenSupplyType = true; // set supply to FINITE
token.maxSupply = maxSupply;
token.tokenKeys = keys;
token.freezeDefault = false;
token.expiry = createAutoRenewExpiry(address(this), autoRenewPeriod); // Contract automatically renew by himself
(int responseCode, address createdToken) = HederaTokenService.createNonFungibleToken(token);
if(responseCode != HederaResponseCodes.SUCCESS){
//revert("Failed to create non-fungible token");
}
return createdToken;
}
function mintNft(
address token,
bytes[] memory metadata
) external returns(int64){
(int response, , int64[] memory serial) = HederaTokenService.mintToken(token, 0, metadata);
if(response != HederaResponseCodes.SUCCESS){
revert("Failed to mint non-fungible token");
}
return serial[0];
}
function transferNft(
address token,
address receiver,
int64 serial
) external returns(int){
HederaTokenService.associateToken(receiver, token);
int response = HederaTokenService.transferNFT(token, address(this), receiver, serial);
if(response != HederaResponseCodes.SUCCESS){
revert("Failed to transfer non-fungible token");
}
return response;
}
}