Input file for Script

I’ve a script like the follwing

upgradeInven : Party → [InvenKey] → [Int] → Script ()

And, I hope to run this script

daml script --dar $(dar_path) --script-name Scripts.InitializeScript:upgradeInven --ledger-host $(ledger_host) --ledger-port $(ledger_port) --input-file exclude-keys.json

How can I build exclude-keys.json to run the script?

Hi @star123good,

Please note this section from our documentation:

If the --input-file flag is specified, the --script-name flag must point to a function of one argument returning a Script , and the function will be called with the result of parsing the input file as its argument. For example, we can initialize our ledger using the initialize function defined above.

So to be able to use the --input-file option, first you need to define a data type that encapsulates all your arguments. The easiest way to generate the json is to do it from another daml script which populates and returns an instance of that same data type, using the --output-file option.

Hi, @Mate_Varga

data UpgradeData = UpgradeData with
operator : Party
invenkeys : [InvenKey]
nums: [Int]

upgradeInven : UpgradeData→ Script ()

And, in exclude-keys.json
“operator”: “Operator”,
“invenkeys”: ,

Is this correct?

Hi @star123good,

I recommend you run a script just to produce an example, but basically yes.
I have mocked up your type and ran it to produce an output:

data InvenKey = InvenKey with
  keyAttr : Text

data UpgradeData = UpgradeData with
  operator : Party
  invenkeys : [InvenKey]
  nums: [Int]

outputData : Script UpgradeData
outputData = do
  let ik0 = (InvenKey "key0attr")
  let ik1 = (InvenKey "key1attr")
  party <- allocateParty "Party"
  pure ( UpgradeData party [ik0,ik1] [0,1,2] )

The output produced when I ran this script with the --output-file option:

  "operator": "party-575096f2-7863-4a38-88d4-441642e61d23::1220c7f8a6da7b70b9daefea37d4d52b7114e5cedeb6df10e76467820af8410f9a9b",
  "invenkeys": [{
    "keyAttr": "key0attr"
  }, {
    "keyAttr": "key1attr"
  "nums": [0, 1, 2]