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 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
17 changes: 10 additions & 7 deletions cadence/contract.cdc
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
pub resource NFTMinter {
access(all)
resource NFTMinter {

// mintNFT mints a new NFT with a new ID
// and deposit it in the recipients collection using their collection reference
pub fun mintNFT(
// and deposits it in the recipient's collection using their collection reference
access(all)
fun mintNFT(
recipient: &{NonFungibleToken.CollectionPublic},
name: String,
description: String,
Expand All @@ -11,8 +13,8 @@ pub resource NFTMinter {
will: String,
determination: String
) {
// create a new NFT
var newNFT <- create NFT(
// Create a new NFT
let newNFT <- create NFT(
id: NewExampleNFT.totalSupply,
name: name,
description: description,
Expand All @@ -22,9 +24,10 @@ pub resource NFTMinter {
determination: determination
)

// deposit it in the recipient's account using their reference
// Deposit it in the recipient's account using their reference
recipient.deposit(token: <-newNFT)

// Increment the total supply of NFTs
NewExampleNFT.totalSupply = NewExampleNFT.totalSupply + (1 as UInt64)
}
}
}
21 changes: 11 additions & 10 deletions cadence/transaction.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@ import NewExampleNFT from 0x02
// It must be run with the account that has the minter resource
// stored in /storage/NFTMinter

transaction{
transaction {

// local variable for storing the minter reference
let minter: &NewExampleNFT.NFTMinter
// Local variable for storing the minter reference
let minter: auth(MinterEntitlement) &NewExampleNFT.NFTMinter

prepare(signer: AuthAccount) {
// borrow a reference to the NFTMinter resource in storage
self.minter = signer.borrow<&NewExampleNFT.NFTMinter>(from: NewExampleNFT.MinterStoragePath)
?? panic("Could not borrow a reference to the NFT minter")
prepare(signer: auth(Storage, Capabilities) &Account) {
// Borrow a reference to the NFTMinter resource in storage
self.minter = signer.capabilities.storage.borrow<&NewExampleNFT.NFTMinter>(
from: NewExampleNFT.MinterStoragePath
) ?? panic("Could not borrow a reference to the NFT minter")
}

execute {
// Borrow the recipient's public NFT collection reference
let receiver = getAccount(0x02)
.getCapability(NewExampleNFT.CollectionPublicPath)
.borrow<&{NonFungibleToken.CollectionPublic}>()
.capabilities
.borrow<&{NonFungibleToken.CollectionPublic}>(NewExampleNFT.CollectionPublicPath)
?? panic("Could not get receiver reference to the NFT Collection")

// Mint the NFT and deposit it to the recipient's collection
Expand All @@ -36,4 +37,4 @@ transaction{

log("Minted an NFT")
}
}
}
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ export const mintNFT = {
transactionCode: transactionPath,
transactionExplanation: transactionExplanationPath,
filters: {
difficulty: "beginner"
}
difficulty: "beginner",
},
};