Running scripts with parameters

Hello, I’m a new developer learning flow particularly interested in making a 3rd party application for nba top shot. I’ve been following the readme from the nba top shot smart contract repo and so far I’ve been able to run the scripts which require no params fine. However for scripts that require a parameter such as


pub fun main(playID: UInt32): {String:String} {
    let metadata = TopShot.getPlayMetaData(playID: playID) ?? panic("Play doesn't exist")
    log(metadata)
    return metadata
}

what is the correct way to pass this param if we are using the flow CLI? I’m currently calling the script from the cli as such flow scripts execute transactions/scripts/plays/get_play_metadata.cdc --host access.mainnet.nodes.onflow.org:9000

If I overlooked something please let me know, thank you!

Hi @JapaneseCatGuy you can pass arguments like so:

flow scripts execute script.cdc --args="[{\"type\": \"String\", \"value\": \"Hello, Cadence\"}]"

We will make sure to update the docs.

1 Like

Thank you for the response @sideninja . Is this already in the current version of the flow-cli?
I’m using v0.14.0 of flow cli, and get the error unknown flag: --args when I try to run the script using the flag. I saw Pass arguments to scripts and transactions by MaxStalker · Pull Request #51 · onflow/flow-cli · GitHub was merged, but wasn’t sure if it’s already released.

@JapaneseCatGuy You’re right, the release with this new functionality is not yet released but will be soon :crossed_fingers: - feel free to provide any feedback on CLI or your development experience. It’s important to us to hear it.