<blockquote>
<p>{
&quot;constructor&quot;: 0,
&quot;fields&quot;: {int: 42}
}</p>
</blockquote>
<p>This isn't valid because <code>fields</code> must be an array. The index of the constructor and fields will match the order of types defined for the validator script. For a Bid you'd use constructor 0 with a single field which is a json representation of TradeDetails (bytestring, bytestring, integer).
It is easier and safer to use <code>scriptDataToJson</code>.</p>

CC BY-SA 4.0
2022-05-19T16:40:55.550Z
got it. thanks :)
pprs
CC BY-SA 4.0
2022-12-08T06:46:31.980Z
This answer helps me, indirectly. Thanks
Adam
CC BY-SA 4.0
2022-04-19T13:46:43.077Z
2022-04-19T13:46:43.077Z
james
<p>Have a look at the following source <a href="https://input-output-hk.github.io/cardano-node/cardano-api/Cardano-Api-ScriptData.html#g:1" rel="noreferrer">Cardano-Api Haddock</a>. Here you will find all about the conversion between Haskell data types and the Json format the cardano-cli uses.</p>
<p>I noticed that you used the marketplace of SpaceBudz as an example, so lets have a look at the other code in that repository. Notice the line <a href="https://github.com/Berry-Pool/spacebudz/blob/fed5d9051953639d38d70c2c6e6948542787e547/src/cardano/market/ghc/plutus-trade.hs#L99" rel="noreferrer">99</a>.</p>
<pre><code>print $ &quot;Datum value: &quot; &lt;&gt; encode (scriptDataToJson ScriptDataJsonDetailedSchema $ fromPlutusData (Plutus.toData offerDatum))
</code></pre>
<p>Here that function prints the <code>offerDatum</code> defined at line 85. You see here how the function from the cardano-api are used and then encoded to convert the datum to a json form? Here the <code>&lt;&gt;</code> symbol just means concatenate the two strings.</p>
<p>For a more detailed explanation of what is going on in this line have a look at the PPP cohort 3 lecture 3 from lars on <a href="https://www.youtube.com/watch?v=ABtffZPoUqU&amp;list=PLNEK_Ejlx3x2zxcfoVGARFExzOHwXFCCL&amp;index=6" rel="noreferrer">youtube</a>.</p>

CC BY-SA 4.0
2022-05-19T16:40:51.770Z
got it. thanks :)
pprs
CC BY-SA 4.0
2022-04-04T08:16:00.450Z
2022-04-04T08:16:00.450Z
Fermat
<p>I'm trying to deploy a smart contract on cardano-cli after its implementation on plutus playground.</p>
<p>Imagine that I have:</p>
<pre><code>data TradeDatum = StartBid | Bid TradeDetails | Offer TradeDetails 
    deriving (Generic, ToJSON, FromJSON)


data TradeDetails = TradeDetails
    { tradeOwner :: !PubKeyHash
    , budId :: !BuiltinByteString
    , requestedAmount :: !Integer
    } deriving (Generic, ToJSON, FromJSON)
</code></pre>
<p>How can I write this in an example JSON to submit on cardano-cli? I saw an example with int: 42,</p>
<pre><code>{
  &quot;constructor&quot;: 0,
  &quot;fields&quot;: {int: 42}
}
</code></pre>
<p>but I really don't know.</p>
<ol>
<li>How can I define the different types?</li>
<li>Inside the tradedetails, how can I define? and for example, how to express the pubkeyhash?</li>
</ol>
<p>Can you give me an exmaple? There are some tutorials with the types of data that I can write inside the JSON (like int)?</p>
<p>Thanks.</p>

<plutus><cardano-cli><datum><redeemer>
Plutus datum and redeemer on cardano-cli
# Plutus datum and redeemer on cardano-cli

(Asked by: username_0 on 2022-03-30)

I'm trying to deploy a smart contract on cardano-cli after its implementation on plutus playground.
Imagine that I have:
data TradeDatum = StartBid | Bid TradeDetails | Offer TradeDetails 
    deriving (Generic, ToJSON, FromJSON)


data TradeDetails = TradeDetails
    { tradeOwner :: !PubKeyHash
    , budId :: !BuiltinByteString
    , requestedAmount :: !Integer
    } deriving (Generic, ToJSON, FromJSON)

How can I write this in an example JSON to submit on cardano-cli? I saw an example with int: 42,
{
  "constructor": 0,
  "fields": {int: 42}
}

but I really don't know.

How can I define the different types?
Inside the tradedetails, how can I define? and for example, how to express the pubkeyhash?

Can you give me an exmaple? There are some tutorials with the types of data that I can write inside the JSON (like int)?
Thanks.

**Tags:** plutus, cardano-cli, datum, redeemer

---

## 2 answers

### Answer by username_3 on 2022-04-04. Score: 5 | Accepted answer

Have a look at the following source Cardano-Api Haddock. Here you will find all about the conversion between Haskell data types and the Json format the cardano-cli uses.
I noticed that you used the marketplace of SpaceBudz as an example, so lets have a look at the other code in that repository. Notice the line 99.
print $ "Datum value: " <> encode (scriptDataToJson ScriptDataJsonDetailedSchema $ fromPlutusData (Plutus.toData offerDatum))

Here that function prints the offerDatum defined at line 85. You see here how the function from the cardano-api are used and then encoded to convert the datum to a json form? Here the <> symbol just means concatenate the two strings.
For a more detailed explanation of what is going on in this line have a look at the PPP cohort 3 lecture 3 from lars on youtube.

> **Comments:**
> **username_0**: got it. thanks :)  

---

### Answer by username_1 on 2022-04-19. Score: 3

> {
> "constructor": 0,
> "fields": {int: 42}
> }

This isn't valid because `fields` must be an array. The index of the constructor and fields will match the order of types defined for the validator script. For a Bid you'd use constructor 0 with a single field which is a json representation of TradeDetails (bytestring, bytestring, integer).
It is easier and safer to use `scriptDataToJson`.

> **Comments:**
> **username_0**: got it. thanks :)  
> **username_2**: This answer helps me, indirectly. Thanks  

---

