Smart Contracts

Transactions to work with smart contracts

In this guide, you will understand all logics you need to know for interacting with smart contracts with MeshTxBuilder.

In Cardano, whenever you need the nodes' computing power to execute a smart contract, you need to provide collateral to prevent spamming. You will see this is everywhere when script execution is needed in below's examples, and here's how you can do so:

Lock Assets

Locking assets meaning sending value to a script address with datum.

Same as Transaction demo, we will lock selected assets from your wallet in analways succeed smart contract. We use one API to represent sending value, another API to represent attaching datum to complete the locking assets process:

The lower level APIs support providing your datum in all Mesh Data (default), JSON and CBOR representations. For details and helper utilities, please check Data section.

Lock Assets

Lock assets in a Plutus script

Connect wallet to run this demo

No wallets installed

Unlock Assets

Unlocking with MeshTxBuilder starts with anyone of the below script version indicators:

Followed by specifying the exact script input to spend with:

In Cardano, if you want to unlock assets from a script address, you have to provide 3 other necessary information apart from .txIn() itself. They are:

  • Actual script
  • Datum of the input
  • Redeemer of the unlock

Actual script

The actual script can be either provided by transaction builder or referenced from an UTxO onchain.

  • (i) Reference script
  • (ii) Supplying script

Datum of the input

Similar to script, datum can also either be provided by transaction builder or as inline datum.

  • (i) Referencing inline datum
  • (ii) Supplying datum

Redeemer of the unlock

Redeemer can be provided in different data types. If your MeshTxBuilder does not include an evaluator instance, you can also provide your budget for the unlock with this redeemer endpoint

An example of complete set of endpoints to unlock assets from a script address:

Unlock Assets

Unlock assets in a Plutus script

Connect wallet to run this demo

No wallets installed

Minting Assets with Plutus Script

Minting Plutus tokens with MeshTxBuilder starts with anyone of the below script version indicators:

Followed by specifying the minting information:

Similar to unlocking assets, minting or burning Plutus tokens require providing redeemer and scripts. However, no datum information is needed in minting or burning.

Script of the token

The actual script can be either provided by transaction builder or referenced from an UTxO onchain.

  • (i) Reference script
  • (ii) Supplying script

Redeemer of the mint

Redeemer can be provided in different data types. If your MeshTxBuilder does not include an evaluator instance, you can also provide your budget for the unlock with this redeemer endpoint

Mint Assets with Plutus Script

Mint native assets with Plutus Script. For this example, the Plutus script expects a data field of 'mesh'.

Connect wallet to run this demo

No wallets installed

Send Reference Scripts Onchain

For all smart contract executions, you have option to provide script as referencing onchain. To do so, you must send the script onchain first. You can attach the script like attaching datum to a output with this:

Send Reference Script

Provide script as referencing onchain

Connect wallet to run this demo

No wallets installed