Escrow
Secure exchange of assets between two parties
The escrow smart contract allows two parties to exchange assets securely. The contract holds the assets until both parties agree and sign off on the transaction.
There are 4 actions available to interact with this smart contract:
- initiate escrow and deposit assets
- deposit assets
- complete escrow
- cancel escrow
Install package
First you can to install the @meshsdk/contracts
package:
Initialize the contract
To initialize the escrow, we need to initialize a provider, MeshTxBuilder
and MeshEscrowContract
.
Both on-chain and off-chain codes are open-source and available on Mesh Github Repository.
Mint a Mesh Token to try demos
Initiate Escrow
An escrow is initiated by one of the party, user A, by locking assets to the escrow contract.
initiateEscrow()
initiate an escrow. The function accepts the following parameters:
- escrowAmount (Asset[]) - a list of assets user A is trading
The function returns a transaction hex if the escrow is successfully initiated.
Initiate an escrow, in this demo, person A is initiating the escrow and deposit ADA.
Connect wallet to run this demo
Recipient Deposit
User B can deposit assets into the escrow after initiation step (initiateEscrow()
).
recipientDeposit()
deposit assets into the escrow. The function accepts the following parameters:
- escrowUtxo (UTxO) - the utxo of the transaction on the contract
- depositAmount (Asset[]) - a list of assets user B is trading
We have provided a very handle function, getUtxoByTxHash
, which will return the UTxO object for a given transaction hash.
Deposit funds into the escrow for trade. In this demo, person B is depositing an asset into the escrow.
Connect wallet to run this demo
Complete Escrow
A user can complete an escrow if the terms of the agreement are met. The completion can be initiated by any recipient of the escrow.
completeEscrow()
complete an escrow. The function accepts the following parameters:
- escrowUtxo (UTxO) - the utxo of the transaction in the script to be completed
Important: This is a multi-signature transaction. Both users must sign the transaction to complete the escrow.
A successful completion of the escrow will result in the assets being swapped between the two parties.
User A completes the escrow by calling the `completeEscrow()` function and partial sign the transaction.
Connect wallet to run this demo
The signed transaction will be handled to User B to sign the transaction and submits it to the blockchain to complete the escrow.
Connect wallet to run this demo
Cancel Escrow
A user can cancel an escrow if the other party fails to fulfill the terms of the agreement. Cancel can be initiated by any users who have partcipated in the escrow and can be done at any time before complete. Canceling the escrow will return the assets to the respective users.
cancelEscrow()
cancel an escrow. The function accepts the following parameters:
- escrowUtxo (UTxO) - the utxo of the transaction to be canceled
We have provided a very handle function, getUtxoByTxHash
, which will return the UTxO object for a given transaction hash.
Any users who have partcipated in the escrow and can cancel the trade at any time before complete.
Connect wallet to run this demo