0

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 ()

2
  • Can you please add the mustPayToOtherScript code you wrote?
    – Mateus
    Sep 16 at 10:51
  • Sure, I am trying to create a uniswap type pool UTXO which stores the liquidity token supply in its datum (hence of Integer type) Sep 17 at 20:24
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.