How can I call Endpoint via cardano-cli transaction build command?

Hello, everyone
How can I call Endpoint via cardano-cli transaction build command?

What do you mean by “calling an endpoint”?

cardano-clis idea is to use a cardano-node running on the same system through a Unix socket file.

If you want to query UTxOs, submit transactions, … through something on the net instead of running your own node, an API like Blockfrost or Koios is probably better suited.

And you would write something in the programming language of your choice to use these APIs.

I kind of understand where you coming from. Correct me if I’m wrong. You see the code in Plutus Pioneer Program / Plutus Playground that look like:

give :: forall w s e. AsContractError e => Contract w s e ()
give gp = do

grab :: forall w s e. AsContractError e => Contract w s e ()
grab = do

endpoints :: Contract () Schems Text ()
endpoints = awaitPromise (give' `select` grab') >> endpoints
    give' = endpoint @"give" $ const give
    grab' = endpoint @"grab" $ const grab

And perhaps you already test the contract off-chain with the emulator, successfully. Now you do the serialization and get “script.plutus” and you wanna test it on-chain by sending actual transaction with cardano-cli.

If the above is correct, then here is the answer:

The “Endpoints” in the code above are for off-chain testing. In production (or on-chain testing) you don’t call the endpoints. They are not even included in “script.plutus”. All the script does is to provide address and validate transactions.

In production, you construct the datum and the redeemer and send transactions: what the … you see above. Except that now you don’t do it with Plutus.

But do it with cardano-cli or other tools like Lucid and Mesh.

Hello, @AdamYoung
I understand what you mean.
By the way, I can’t know how I can make Datum and Redeemer for the endpoint.

Maybe you can start with this example from Mesh

Again when interact with the smart contract on-chain, there is no “endpoint”. Just the script, datum and redeemer.

@AdamYoung , I am in the example as your guide.

But I am getting these errors.
Sorry, but how can I solve this ?

To be honest, I haven’t tried mesh in this particular use case. I mostly use Lucid.

However, you should ask the question in I think it is more suitable for this kind of code-level question. Also you should provide more details. For example, how you define scriptAddress, asset, and datum and the relevant part of rest of the code.

Last time I ask question about Mesh, the Mesh team themselves comes to answer.

Just make sure you have “mesh” tagged to the question.

@AdamYoung , sorry, but could you help with this error ?

According the error message “…but no collateral inputs are added”, it appears you have not set/enabled collateral on the wallet you are using.

The collateral is an amount in ADA which will be used in case the smart contract fails to execute on-chain and it is required in order to build a transaction which spends from a script address. It is highly unlikely that a script will fail on-chain, but the collateral mechanism helps reduce the likelihood of a denial of service attack. You can read more about collateral here

Using Nami, for example, here’s how you set the collateral


1 Like

Thanks, but I am getting this error.