End-to-End Next.js Escrow Guide
Build a Cardano escrow application with wallet connectivity, fund locking and unlocking, and transaction monitoring by interacting with a deployed smart contract.
Last updated
Was this helpful?
Build a Cardano escrow application with wallet connectivity, fund locking and unlocking, and transaction monitoring by interacting with a deployed smart contract.
Last updated
Was this helpful?
This guide walks you through building a Cardano escrow application using Next.js and the Weld wallet connector. You'll create a web application that demonstrates the practical application of Cardano smart contracts through a real-world escrow use case.
See the below guides for more details:
This application demonstrates the complete lifecycle of smart contract interaction on Cardano:
Connect Wallet: Users connect their Cardano wallet to establish their blockchain identity
Lock Funds: Users lock ADA in a smart contract, specifying themselves as the future recipient
Monitor Status: Users track the status of their locked funds in real-time
Unlock Funds: When ready, users reclaim their funds by meeting the contract's conditions
Through this process, users experience firsthand how Cardano's eUTXO model and validator scripts work together to create secure, programmable transactions.
The principles demonstrated in this escrow application can be extended to build a variety of real-world solutions:
Marketplace Escrow: Hold buyer funds until the seller confirms delivery of goods or services
Rental Security Deposits: Lock tenants' deposits and release after lease terms are met
Milestone Payments: Release funds to contractors upon completion of deliverables
Token Vesting: Gradually unlock tokens to team members based on a schedule
Shared Savings: Create group savings where funds unlock only when a goal is reached
With the Cardano Escrow application, users can:
Lock ADA at a script address with owner information stored in the datum
Monitor transaction status in real-time
Unlock funds when ready
Signature verification ensures only the rightful owner can access funds
Use the special message from your redeemer ("Hello, World!") to unlock funds. This message is required by the smart contract in order to spend the locked funds.
This application uses a Hello World smart contract to create a secure escrow by enforcing two simple conditions:
The transaction must include the specific message "Hello, World!" in the redeemer
field
The transaction must be signed by the owner's key specified in the datum
When both conditions are met, the validator returns true
and the locked funds can be spent.
Before starting, ensure you have:
Node.js 18+ installed
Basic familiarity with React and Next.js
An Anvil API key (for transaction building and submission)
A deployed Hello World smart contract with the validator hash.
This tutorial is divided into six progressive modules, each focusing on a specific aspect of the escrow application:
Initialize a Next.js project
Set up essential dependencies and project structure
Connect to Cardano wallets using the Weld library
Implement wallet connection and state management
Create the interface to lock funds in the smart contract
Build and submit lock transactions via Anvil API
Develop a dashboard to monitor transaction status
Implement transaction history storage and retrieval
Add real-time Cardano monitoring through webhooks
Update transaction status as blockchain state changes
Implement the unlock functionality to complete the escrow cycle
Create the redeemer with the specific message and handle signing
Security: Never expose API keys or private credentials in client-side code
Testing: Always test your application on testnet before deploying to mainnet
Error Handling: Implement comprehensive error handling for all blockchain operations
Units: Remember that 1 ADA = 1,000,000 Lovelace when calculating amounts
If you have not already, make sure you have a deployed smart contract and have a validator hash handy.
Connect any supported Cardano wallet (Eternl, Lace, etc.)
A Cardano wallet with testnet ADA (Eternl, Lace, etc.) See the if you need testnet ADA.