Running local emulator issues

Hey, so when trying to run a simple tutorial script locally I keep getting this error.

Failed to submit executable script: client: rpc error: code = Internal desc = failed to encode value: unsupported value: <nil>, <nil>

For more context, when using the flow playground I experience no issues with the code. My local machine has the cadence vs code extension installed and flow cli. I used flow init and flow emulator start to start the emulator. I am able to run the transaction and get a correct response but it only happens with the script.

import PinataPartyContract from 0xf8d6e0586b0a20c7

pub fun main() : {String : String} {
    let nftOwner = getAccount(0xf8d6e0586b0a20c7)
    // log("NFT Owner")    
    let capability = nftOwner.getCapability<&{PinataPartyContract.NFTReceiver}>(/public/NFTReceiver)

    let receiverRef = capability.borrow()
        ?? panic("Could not borrow the receiver reference")

    return receiverRef.getMetadata(id: 1)
}

I fairly new to blockchain and flow so I think thereโ€™s probably something simple in the configuration Iโ€™m missing. My guess is the contract isnโ€™t importing correctly, but any help would be greatly appreciated.

I was following the medium article when running into this issue: https://medium.com/pinata/how-to-create-nfts-like-nba-top-shot-with-flow-and-ipfs-701296944bfe

Hi @jmtimper!

I ran into the same problem following that tutorial.

Two changes made the script work for me. Here they areโ€ฆ

Use flow-cli's new script command format

:warning:Heads up, be sure youโ€™re running the latest flow-cli (0.16.0). There was a breaking change for script execution in 0.15.0.

The medium tutorial says to run this command:

flow scripts execute ./scripts/CheckTokenMetadata.cdc

However, this is no longer the way. Run this to see the help docs:

flow scripts execute --help

This is the new format:

flow scripts execute --code=scripts/CheckTokenMetadata.cdc

Ensure the token was properly minted

Even using the new script API wonโ€™t work if the token wasnโ€™t properly minted. Iโ€™m not sure what I did wrong, but I kept seeing this in the emulator terminal when running the script:

WARN[0004] ERR [f0fd70] Execution failed:

error: cannot find declaration PinataPartyContract in `f8d6e0586b0a20c7.PinataPartyContract

To resolve this, I followed these steps:

  • :recycle:Stop and restart the emulator.
  • run the deploy command again.
  • run the transaction to mint the NFT again
  • run the script again
  • :partying_face:See the metadata!

A happy log stream in the emulator terminal should look like this:

Best of luck to you as you learn!

I am on version v0.17.0 and I have the same issue. I followed all recommended steps and I am still not able to get rid of this error. Any ideas?

I finally tried this and this fixed my issue:

flow accounts add-contract <name> <filename>

Could you elaborate?