Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

metadata.gno

1.44 Kb · 49 lines
 1package nft
 2
 3import (
 4	"chain/runtime"
 5
 6	"gno.land/p/g17khqpukees4237dtn3astzapmp462vjhsz6st4/settlers/nft/v0"
 7	"gno.land/p/nt/grc721/v0"
 8)
 9
10// TokenURI returns the Settler image as an SVG data URI.
11// Wallets such as Adena read TokenURI directly as the token image,
12// so this must be the image itself. The metadata lives in TokenMetadata.
13func TokenURI(tid grc721.TokenID) (string, error) {
14	traits, err := TraitsOf(tid)
15	if err != nil {
16		return "", err
17	}
18
19	return nft.RenderDataURI(traits, nft.Options{Size: nft.CanonicalSize}), nil
20}
21
22// TokenMetadata returns a JSON string with the metadata of a Settler
23// in the format the Adena wallet can understand.
24func TokenMetadata(tid grc721.TokenID) (string, error) {
25	traits, err := TraitsOf(tid)
26	if err != nil {
27		return "", err
28	}
29
30	var attrs string
31	for i, attr := range traits.Attributes() {
32		if i > 0 {
33			attrs += ","
34		}
35
36		attrs += `{"traitType":"` + attr.Type + `","value":"` + attr.Value + `"}`
37	}
38
39	return `{"name":"Settler #` + string(tid) + `",` +
40		`"description":"Soulbound gnome of the early settlers of Gno.land. ` + nft.Credits + `",` +
41		`"image":"` + nft.RenderDataURI(traits, nft.Options{Size: nft.CanonicalSize}) + `",` +
42		`"externalUrl":"` + ExternalURL(tid) + `",` +
43		`"attributes":[` + attrs + `]}`, nil
44}
45
46// ExternalURL returns the URL to a Settler profile page.
47func ExternalURL(tid grc721.TokenID) string {
48	return "https://" + runtime.ChainDomain() + RealmPath + ":token/" + string(tid)
49}