nft.gno
1.33 Kb ยท 70 lines
1package mynft10
2
3import (
4 "strconv"
5 "chain/runtime"
6
7 "gno.land/p/demo/tokens/grc721"
8 "gno.land/p/nt/ufmt"
9 "gno.land/r/pierre115/nftregistry8"
10)
11
12type NFTCollection interface {
13 grc721.IGRC721
14 Mint(to address, tid grc721.TokenID) error
15 Getter() grc721.NFTGetter
16}
17
18var (
19 nft NFTCollection
20 nextTokenId = 1
21 myRealmAddr = runtime.CurrentRealm().Address()
22)
23
24func init() {
25 nft = grc721.NewBasicNFT("Test NFT Collection 10", "TEST10")
26}
27
28// Register registers this collection on the NFT registry
29func Register(_ realm) {
30 nftregistry8.RegisterCollection(
31 myRealmAddr,
32 "Test NFT Collection 10",
33 "TEST10",
34 "art",
35 "First wars",
36 "https://example.com",
37 false,
38 nft.Getter(),
39 )
40}
41
42func MintNFT(_ realm) int {
43 caller := runtime.PreviousRealm().Address()
44 tokenId := grc721.TokenID(strconv.Itoa(nextTokenId))
45
46 err := nft.Mint(caller, tokenId)
47 if err != nil {
48 panic(err.Error())
49 }
50
51 nextTokenId++
52 return nextTokenId - 1
53}
54
55func SetApprovalForAll(_ realm, operator address, approved bool) {
56 err := nft.SetApprovalForAll(operator, approved)
57 if err != nil {
58 panic(err.Error())
59 }
60}
61
62func Getter() grc721.NFTGetter {
63 return nft.Getter()
64}
65
66func Render(path string) string {
67 output := "# My test collection\n\n"
68 output += "## test 8\n\n"
69 output += ufmt.Sprintf("**NftRealmAddr:** %d\n\n", myRealmAddr.String())
70 return output
71}