<p>Your off-chain code is using <code>mustPayToTheScript</code> and not <code>mustPayToOtherScript</code>. It's important to note the difference, since <code>mustPayToTheScript</code> will require a datum with the type you defined in <code>poolInst'</code>, while <code>mustPayToOtherScript</code> will require a datum of type <code>Datum</code>.</p>
<p>So, I will assume you want to use the latter. In this case, you need to convert your variable of type <code>Integer</code> to a variable of type <code>Datum</code>. This can be easily done with <code>(Datum $ PlutusTx.toBuiltinData lt)</code>.</p>
<p>Assuming your logic and other components are working, your code would look like the following:</p>
<pre><code>start :: AsContractError e =&gt; Promise () OwnerSchema e ()
start = endpoint @&quot;start&quot; $ \const -&gt; do
    pkh &lt;- pubKeyHash &lt;$&gt; ownPubKey
    let 
        tokenAAmount = 10000000000 
        tokenBAmount = 1000000000000
        lt = 100000000000
        value = (V.assetClassValue poolNFT 1) &lt;&gt;
                (V.assetClassValue tokenA tokenAAmount) &lt;&gt;
                (V.assetClassValue tokenB tokenBAmount)
        tx   = mustPayToOtherScript (Datum $ PlutusTx.toBuiltinData lt) value 
    ledgerTx &lt;- submitTxConstraints poolInst' tx
    void $ awaitTxConfirmed $ txId ledgerTx
    void $ waitNSlots 1
    logInfo @String $ printf &quot;created pool UTXO %s at validator hash %s&quot; (show poolParams) (show $ orderBoxVH')
    return ()
</code></pre>
<p>Just so it gets easy to debug in the future, I would suggest you to create a function focused specifically in the contract and another function for handling endpoints.</p>

CC BY-SA 4.0
2021-09-17T21:06:27.263Z
2021-09-17T21:06:27.263Z
Mateus
<p>In the onchain validator I used Integer type for Datum and everything was fine
but when I want to use mustPayToOtherScript tx constraint in the offchain code I get the following error:</p>
<pre><code> • Couldn't match expected type ‘Datum’ with actual type ‘Integer’
 • In the second argument of ‘mustPayToOtherScript’
</code></pre>
<p>Edit: offchain code</p>
<pre><code>start :: AsContractError e =&gt; Promise () OwnerSchema e ()
start = endpoint @&quot;start&quot; $ \const -&gt; do
    pkh &lt;- pubKeyHash &lt;$&gt; ownPubKey
    let 
        tokenAAmount = 10000000000 
        tokenBAmount = 1000000000000
        lt = 100000000000
        value = (V.assetClassValue poolNFT 1) &lt;&gt;
                (V.assetClassValue tokenA tokenAAmount) &lt;&gt;
                (V.assetClassValue tokenB tokenBAmount)
        tx   = mustPayToTheScript (lt) value 
    ledgerTx &lt;- submitTxConstraints poolInst' tx
    void $ awaitTxConfirmed $ txId ledgerTx
    void $ waitNSlots 1
    logInfo @String $ printf &quot;created pool UTXO %s at validator hash %s&quot; (show poolParams) (show $ orderBoxVH')
    return ()

</code></pre>

CC BY-SA 4.0
2021-09-16T10:51:55.317Z
Can you please add the `mustPayToOtherScript` code you wrote?
Mateus
CC BY-SA 4.0
2021-09-17T20:24:15.220Z
Sure, I am trying to create a uniswap type pool UTXO which stores the liquidity token supply in its datum (hence of Integer type)
Anh Dũng Lê
<plutus>
`Integer` as `Datum` in offchain code
# `Integer` as `Datum` in offchain code

(Asked by: username_0 on 2021-09-15)

In the onchain validator I used Integer type for Datum and everything was fine
but when I want to use mustPayToOtherScript tx constraint in the offchain code I get the following error:
 • Couldn't match expected type ‘Datum’ with actual type ‘Integer’
 • In the second argument of ‘mustPayToOtherScript’

Edit: offchain code
start :: AsContractError e => Promise () OwnerSchema e ()
start = endpoint @"start" $ \const -> do
    pkh <- pubKeyHash <$> ownPubKey
    let 
        tokenAAmount = 10000000000 
        tokenBAmount = 1000000000000
        lt = 100000000000
        value = (V.assetClassValue poolNFT 1) <>
                (V.assetClassValue tokenA tokenAAmount) <>
                (V.assetClassValue tokenB tokenBAmount)
        tx   = mustPayToTheScript (lt) value 
    ledgerTx <- submitTxConstraints poolInst' tx
    void $ awaitTxConfirmed $ txId ledgerTx
    void $ waitNSlots 1
    logInfo @String $ printf "created pool UTXO %s at validator hash %s" (show poolParams) (show $ orderBoxVH')
    return ()

**Tags:** plutus
> **Comments:**
> **username_1**: Can you please add the `mustPayToOtherScript` code you wrote?  
> **username_0**: Sure, I am trying to create a uniswap type pool UTXO which stores the liquidity token supply in its datum (hence of Integer type)  

---

## 1 answers

### Answer by username_1 on 2021-09-17. Score: 1 | Accepted answer

Your off-chain code is using mustPayToTheScript and not mustPayToOtherScript. It's important to note the difference, since mustPayToTheScript will require a datum with the type you defined in poolInst', while mustPayToOtherScript will require a datum of type Datum.
So, I will assume you want to use the latter. In this case, you need to convert your variable of type Integer to a variable of type Datum. This can be easily done with (Datum $ PlutusTx.toBuiltinData lt).
Assuming your logic and other components are working, your code would look like the following:
start :: AsContractError e => Promise () OwnerSchema e ()
start = endpoint @"start" $ \const -> do
    pkh <- pubKeyHash <$> ownPubKey
    let 
        tokenAAmount = 10000000000 
        tokenBAmount = 1000000000000
        lt = 100000000000
        value = (V.assetClassValue poolNFT 1) <>
                (V.assetClassValue tokenA tokenAAmount) <>
                (V.assetClassValue tokenB tokenBAmount)
        tx   = mustPayToOtherScript (Datum $ PlutusTx.toBuiltinData lt) value 
    ledgerTx <- submitTxConstraints poolInst' tx
    void $ awaitTxConfirmed $ txId ledgerTx
    void $ waitNSlots 1
    logInfo @String $ printf "created pool UTXO %s at validator hash %s" (show poolParams) (show $ orderBoxVH')
    return ()

Just so it gets easy to debug in the future, I would suggest you to create a function focused specifically in the contract and another function for handling endpoints.


---

