user1108: I have two main actions that user can do. They both require sending utxos to a script address. The datum I want produced by these two actions are different. I want one of the datum like this
data VotingDatum = VotingDatum
  { projectPubKey :: PaymentPubKeyHash
  , amount :: Integer
  , fund :: Integer
  , paymentPubKey :: PaymentPubKeyHash
  }deriving (Show)

and the other one like this.
data StartDatum = StartDatum
 { startFund :: Integer
 , fundPrize :: Integer
 }deriving (Show)

I was thinking of putting these two in a single data type like this
data ContractDatum = ContractDatum
 { voteDatum :: Maybe VotingDatum
 , startDatum :: Maybe StartDatum
 }

How would i set the value of these fields if i did it like this. Can i do it like this ?
I am currently setting the value of the types like this
start sp = do 
    let dat = StartDatum
                { startFund = spFund sp 
                , fundPrize = spAmount sp
                }

How can i have two different data types for the datum. How can i set the value of it , and how would i access the value of it.

user2335: You can combine the two like this
data DatumAction = VotingDatum | StartDatum

Then you can specify in you validator which case is used like this
mkValidator :: DatumAction -> redeemer -> ScriptContext -> Bool
mkValidator datumAction redeemer context = case datumAction of
    VotingDatum -> do something with type bool
    StartDatum  -> do something with type bool

Hope this helps, also see (1) and (2).

1108: <p>I have two main actions that user can do. They both require sending utxos to a script address. The datum I want produced by these two actions are different. I want one of the datum like this</p>
<pre><code>data VotingDatum = VotingDatum
  { projectPubKey :: PaymentPubKeyHash
  , amount :: Integer
  , fund :: Integer
  , paymentPubKey :: PaymentPubKeyHash
  }deriving (Show)
</code></pre>
<p>and the other one like this.</p>
<pre><code>data StartDatum = StartDatum
 { startFund :: Integer
 , fundPrize :: Integer
 }deriving (Show)
</code></pre>
<p>I was thinking of putting these two in a single data type like this</p>
<pre><code>data ContractDatum = ContractDatum
 { voteDatum :: Maybe VotingDatum
 , startDatum :: Maybe StartDatum
 }
</code></pre>
<p>How would i set the value of these fields if i did it like this. Can i do it like this ?
I am currently setting the value of the types like this</p>
<pre><code>start sp = do 
    let dat = StartDatum
                { startFund = spFund sp 
                , fundPrize = spAmount sp
                }
</code></pre>
<p>How can i have two different data types for the datum. How can i set the value of it , and how would i access the value of it.</p>
 2335: <p>You can combine the two like this</p>
<pre><code>data DatumAction = VotingDatum | StartDatum
</code></pre>
<p>Then you can specify in you validator which case is used like this</p>
<pre><code>mkValidator :: DatumAction -&gt; redeemer -&gt; ScriptContext -&gt; Bool
mkValidator datumAction redeemer context = case datumAction of
    VotingDatum -&gt; do something with type bool
    StartDatum  -&gt; do something with type bool
</code></pre>
<p>Hope this helps, also see <a href="https://wiki.haskell.org/Algebraic_data_type" rel="nofollow noreferrer">(1)</a> and <a href="https://www.haskell.org/tutorial/patterns.html" rel="nofollow noreferrer">(2)</a>.</p>
