# Tutorial - Marketplace - marketplace.cdc

**URL:** <https://forum.flow.com/t/tutorial-marketplace-marketplace-cdc/429>\
**Category:** Flow VSCode Extension\
**Created:** [July 17, 2020, 3:40am UTC](https://forum.flow.com/t/tutorial-marketplace-marketplace-cdc/429 "2020-07-17T03:40:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![robinbonnin](https://avatars.discourse-cdn.com/v4/letter/r/b487fb/32.png) [@robinbonnin](https://forum.flow.com/u/robinbonnin)\
**Post date:** [July 17, 2020, 3:40am UTC](https://forum.flow.com/t/tutorial-marketplace-marketplace-cdc/429/1 "2020-07-17T03:40:58Z")

</div>

Hello !

I am trying to complete the Marketplace tutorial, however one piece of codecopied from the tutorial and the playground does not work in the VS Code extension ::

```
        // purchase lets a user send tokens to purchase an NFT that is for sale

            pub fun purchase(tokenID: UInt64, recipient: &AnyResource{NonFungibleToken.NFTReceiver}, buyTokens: @FungibleToken.Vault) {

                pre {

                    self.forSale[tokenID] != nil && self.prices[tokenID] != nil:

                        "No token matching this ID for sale!"

                    buyTokens.balance >= (self.prices[tokenID] ?? UFix64(0)):

                        "Not enough tokens to by the NFT!"

                }

```

The console says loss of ressources.  
I am not sure what to do here.  
Also in the Playground, this part works. However the transaction1 never finishes. So i’m kinda stuck. 😕

Thank you

---

<div class="post-metadata">

**Author:** ![flowjosh](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/flowjosh/32/362_2.png) [@flowjosh](https://forum.flow.com/u/flowjosh)\
**Post date:** [July 17, 2020, 2:21pm UTC](https://forum.flow.com/t/tutorial-marketplace-marketplace-cdc/429/2 "2020-07-17T14:21:32Z")

</div>

@robinbonnin I’m looking into it now. I’ll get back to you when I’ve found out what is happening. We think some of the recent updates to Cadence might have broke some of the tutorials so we are working on fixing them.

---

<div class="post-metadata">

**Author:** ![flowjosh](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/flowjosh/32/362_2.png) [@flowjosh](https://forum.flow.com/u/flowjosh)\
**Post date:** [July 17, 2020, 2:32pm UTC](https://forum.flow.com/t/tutorial-marketplace-marketplace-cdc/429/3 "2020-07-17T14:32:00Z")

</div>

@robinbonnin I’m seeing the same error. This is because we use the optional chaining `if let` to get the price of the token. If the price isn’t found, then the execution would reach the end of the function and the `buyTokens` resource would be lost. we had mistakenly allowed this previously, but have fixed this bug.

To fix this in your code, you can remove the `if let` block and instead force unwrap the optional price.

```auto
    pub fun purchase(tokenID: UInt64, recipient: &AnyResource{NonFungibleToken.NFTReceiver}, buyTokens: @FungibleToken.Vault) {
        pre {
            self.forSale[tokenID] != nil && self.prices[tokenID] != nil:
                "No token matching this ID for sale!"
            buyTokens.balance >= (self.prices[tokenID] ?? UFix64(0)):
                "Not enough tokens to by the NFT!"
        }

        // get the value out of the optional
        let price = self.prices[tokenID]! 

        self.prices[tokenID] = nil

        // deposit the purchasing tokens into the owners vault
        self.ownerVault.deposit(from: <-buyTokens)

        // deposit the NFT into the buyers collection
        recipient.deposit(token: <-self.withdraw(tokenID: tokenID))

        emit TokenPurchased(id: tokenID, price: price)
        
    }

```

I apologize for the inconvenience. I’m working through the tutorials today to make sure they are correct
