Search Apps Documentation Source Content File Folder Download Copy Actions Download

test_basic_nft.gno

1.54 Kb · 72 lines
 1package mynft3
 2
 3import (
 4	"strconv"
 5	"chain/runtime"
 6	"gno.land/p/demo/tokens/grc721"
 7	"gno.land/r/pierre115/nftregistry2"
 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(_ realm) {
30	nftregistry2.RegisterCollection(
31		"Test NFT Collection 3",  // name ← AJOUTÉ
32		"TEST2",                   // symbol ← AJOUTÉ
33		"art",                     // category
34		"My awesome NFT collection", // description
35		"https://example.com",     // externalURL
36		nft.Getter(),              // getter
37	)
38}
39
40// public function to mint an NFT
41func MintNFT(_ realm) int {
42	caller := runtime.PreviousRealm().Address()
43	tokenId := grc721.TokenID(strconv.Itoa(nextTokenId))
44
45	// call of the interface mint method
46	err := nft.Mint(caller, tokenId)  // mint =! Mint
47	if err != nil {
48		panic(err.Error())
49	}
50
51	nextTokenId++
52	return nextTokenId - 1
53}
54
55// SetApprovalForAll
56func SetApprovalForAll(_ realm, operator address, approved bool) {
57	err := nft.SetApprovalForAll(operator, approved)
58	if err != nil {
59		panic(err.Error())
60	}
61}
62
63func Getter() grc721.NFTGetter {
64	return nft.Getter()
65}
66
67func Render(path string) string {
68	output := "# My test collection\n\n"
69	output += "## test 3\n\n"
70
71	return output
72}