test_basic_nft.gno
1.38 Kb ยท 69 lines
1package mynft
2
3import (
4 "strconv"
5 "chain/runtime"
6 "gno.land/p/demo/tokens/grc721"
7 "gno.land/r/pierre115/nftregistry"
8)
9
10// Basic nft interface
11type NFTCollection interface {
12 grc721.IGRC721
13 Mint(to address, tid grc721.TokenID) error
14 Getter() grc721.NFTGetter
15}
16
17var (
18 nft NFTCollection
19 nextTokenId = 1
20)
21
22func init() {
23 nft = grc721.NewBasicNFT("Test NFT Collection", "TEST")
24 // register on nft registry realm dont work in init
25}
26
27// Register registers this collection on the NFT registry
28// Must be called manually after deployment
29func Register() {
30 nftregistry.RegisterCollection(
31 "art", // category
32 "My awesome NFT collection", // description
33 "https://example.com", // externalURL
34 nft.Getter(),
35 )
36}
37
38// public function to mint an NFT
39func MintNFT(_ realm) int {
40 caller := runtime.PreviousRealm().Address()
41 tokenId := grc721.TokenID(strconv.Itoa(nextTokenId))
42
43 // call of the interface mint method
44 err := nft.Mint(caller, tokenId) // mint =! Mint
45 if err != nil {
46 panic(err.Error())
47 }
48
49 nextTokenId++
50 return nextTokenId - 1
51}
52
53// SetApprovalForAll
54func SetApprovalForAll(_ realm, operator address, approved bool) {
55 err := nft.SetApprovalForAll(operator, approved)
56 if err != nil {
57 panic(err.Error())
58 }
59}
60
61func Getter() grc721.NFTGetter {
62 return nft.Getter()
63}
64
65func Render(path string) string {
66 output := "# My test collection\n\n"
67
68 return output
69}