Build Transactions
Build transactions to interact with smart contracts
Create transaction to lock tokens
In this section, we will create a simple UI that allows users to lock assets on the Cardano blockchain.
First, we get initialze the PlutusScript
and resolve the script address:
We are using the `resolvePlutusScriptAddress` function to resolve the script address.
You notice here we use the applyParamsToScript
, which apply parameters to a script allows you to create a custom CIP-57 compliant script based on some inputs. For this script, we don't have any parameters to apply, but simply applied with double CBOR encoding to scriptCbor
.
Next, we get the wallet address hash:
Here, we use the `resolvePaymentKeyHash` function to resolve the payment key hash of the wallet.
Then, we create the Data
(datum) object containing the address hash:
Finally, we prepare the transaction to lock the assets on the Cardano blockchain.
We create the transactions to lock assets on the Cardano blockchain.
Connect wallet to run this demo
Create transaction to redeem tokens
In this section, we will walk you through the process of creating a transaction to redeem tokens.
First, we need to get the script and script address. We can do this by calling the function we created in the previous section.
Next, we need to get the wallet address and its hash. We can do this by calling the function we created in the previous section.
As the contracts requires the owner's address in the datum field, we are creating a new datum with the owner's address. We create the Data
(datum) object containing the address hash:
After that, we get the UTXO in the script based on the datum:
Finally, we prepare the transaction to redeem the tokens:
Here you notice that in the redeemer
. As the validator requires, here we specify Hello, World!
, which is the message we need to provide to unlock the tokens.
For the transaction, we use the redeemValue
function to redeem the locked assets, the sendValue
function to send the assets to the owner's address, and the setRequiredSigners
function to set the required signers.
Create the transactions to unlock assets
Connect wallet to run this demo