Cardano-cli --script-data-file format

Hi! I’ve been reading the format that’s expected for --script-data-file here and it seems that it should be possible to have a string, however, when I run:

cardano-cli transaction hash-script-data --script-data-file data.json, where data.json is:

{
  "constructor": 1,
  "fields": [
    {
      "bytes": "616263"
    },
    {
      "int": 123
    },
    {
      "string": "lol"
    }
  ]
}

cardano-cli barks

Expected a single field named "int", "bytes", "string", "list" or "map".
Unexpected object field(s): {"string":"lol"}

Is there a way to get this metadata in?

as the error say u have both int and string under field… and only one accepted

the error is the same even if data.json is

{
  "constructor": 1,
  "fields": [
    {
      "bytes": "616263"
    },
    {
      "string": "lol"
    }
  ]
}

can u show me the documentation link?

Check this topic perhaps it will help u

I don’t think there’s documentation? The only thing closest to it was the link I put (https://github.com/input-output-hk/cardano-node/blob/f5878f79683770433b65c670b95da5bdc69c365c/cardano-api/src/Cardano/Api/TxMetadata.hs#L504)

check the above topic… perhaps it can help you

You seem to be right that there is a bug there.

As far as I can see, the relevant code is:

And this code is missing the “string” case. Care to file a bug report?

1 Like

Thanks! Yeah, I thought it was a bug… I found the workaround, and that’s just creating a list of the bytes that represent the string, i.e.:

import qualified Data.ByteString as BS
import Data.Text.Encoding as TextEncoding
import Data.Text
let toUTF8Bytes = BS.unpack . TextEncoding.encodeUtf8 . Data.Text.pack
toUTF8Bytes lol

which would return:
[108,111,108], and so you can make a list of bytes or ints, i.e.

{
  "constructor": 1,
  "fields": [
    {
      "int": 108
    },
    {
      "int": 111
    },
    {
      "int": 108
    }
  ]
}

Instead of “string”, try a hex encoded bytes, like this …

{"constructor":0,"fields":[{"bytes":"4173746f72313736"},{"int":1647807616000}]}

You could even put them in a real list if you want to show that they belong together:

{
  "constructor": 1,
  "fields": [
    {
      "bytes": "616263"
    },
    {
      "int": 123
    },
    {
      "list": [
        {
          "int": 108
        },
        {
          "int": 111
        },
        {
          "int": 108
        }
      ]
    }
  ]
}