Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C1.0 migration #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions cadence/contract.cdc
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
//Here is where the rest of your NFT resource code will go...
// Here is where the rest of your NFT resource code will go...
// Below is the metadata functions to include in your NFT resource...
// Checkout the NFT Metadata example to see it all put together

pub fun getViews(): [Type] {
access(all)
fun getViews(): [Type] {
return [
Type<MetadataViews.Display>()
]
}

pub fun resolveView(_ view: Type): AnyStruct? {
access(all)
fun resolveView(_ view: Type): AnyStruct? {
switch view {
case Type<MetadataViews.Display>():
return MetadataViews.Display(
Expand All @@ -21,12 +23,13 @@ pub fun resolveView(_ view: Type): AnyStruct? {
return nil
}

// below is where you will have your metadata in your NFT initialzied
// Below is where you will have your metadata in your NFT initialized
.....

//the following code is in your collections resource
// The following code is in your collections resource

pub fun borrowViewResolver(id: UInt64): &AnyResource{MetadataViews.Resolver} {
access(all)
fun borrowViewResolver(id: UInt64): &AnyResource{MetadataViews.Resolver} {
let nft = &self.ownedNFTs[id] as auth &NonFungibleToken.NFT
let exampleNFT = nft as! &NewExampleNFT.NFT
return exampleNFT as &AnyResource{MetadataViews.Resolver}
Expand Down
9 changes: 4 additions & 5 deletions cadence/transaction.cdc
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import MetadataViews from 0x01

pub fun main(): AnyStruct {
access(all)
fun main(): AnyStruct {
let address: Address = 0x02
let id: UInt64 = 0

let account = getAccount(address)

let collection = account
.getCapability(/public/exampleNFTCollection)
.borrow<&{MetadataViews.ResolverCollection}>()
.capabilities
.borrow<&{MetadataViews.ResolverCollection}>(/public/exampleNFTCollection)
?? panic("Could not borrow a reference to the collection")

let nft = collection.borrowViewResolver(id: id)


// Get the basic display information for this NFT

let display = nft.resolveView(Type<MetadataViews.Display>())

return display
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ export const metadataViews = {
transactionCode: transactionPath,
transactionExplanation: transactionExplanationPath,
filters: {
difficulty: "beginner"
}
difficulty: "beginner",
},
};