Update greattoken_templates.go
@@ -72,3 +72,18 @@ func GenerateInspectNFTScript(nftCodeAddr, userAddr flow.Address, expectedID int
return []byte(fmt.Sprintf(template, nftCodeAddr, userAddr, expectedID, expectedIsSpecial))
}
+
+// GenerateGetNFTIDScript creates a script that retrieves an NFT from storage and returns its ID.
+func GenerateGetNFTIDScript(nftCodeAddr, userAddr flow.Address) []byte {
+ template := `
+ import GreatToken from 0x%s
+
+ pub fun main(): Int {
+ let acct = getAccount(0x%s)
+ let nft = acct.published[&GreatToken.GreatNFT] ?? panic("missing nft")
+ return nft.id()
+ }
+ `
+
+ return []byte(fmt.Sprintf(template, nftCodeAddr, userAddr))
+}
