Escrow
In this session, we will create an escrow.
An escrow on the XRP Ledger allows users to lock XRP and release it under specific conditions. This feature enables conditional payments, ensuring funds are only transferred when criteria are met. If conditions aren't fulfilled, the escrow can be canceled, returning the funds to the sender.
Start coding
Create a new file or edit index.ts
import dayjs from 'dayjs';
import { Client, isoTimeToRippleTime, xrpToDrops } from 'xrpl';
import { generateConditionAndFulfillment, escrowTransaction } from './helpers';
const main = async () => {
console.log('lets get started...');
// Connect the client to the network
const client = new Client('wss://s.altnet.rippletest.net:51233');
await client.connect();
const { wallet: walletOne } = await client.fundWallet();
const { wallet: walletTwo } = await client.fundWallet();
console.log({ walletOne, walletTwo });
};
main();Create the escrow
In order to create an escrow on the XRP Ledger, you need to specify the amount of XRP to lock, the destination account, and the conditions for release, such as a time-based or cryptographic condition. Additionally, you must ensure the transaction is properly signed and submitted to the network, and verify its success to confirm the escrow is active.
Create a helpers.ts file and add the generateConditionAndFulfillment and escrowTransaction function:
Finishing the escrow
To finish an escrow on the XRP Ledger, you must wait until the specified conditions are met, such as a time-based or cryptographic condition. Then, submit an "EscrowFinish" transaction, providing the necessary details like the condition, fulfillment, and sequence number, to release the locked funds to the designated recipient.
After this step, the escrow transaction has been successfully submitted to the XRP Ledger, signaling the completion of the escrow process. The funds should now be released to the designated recipient, provided all conditions have been met. The client is then disconnected from the network, indicating the end of the transaction session.
Extra credits
Canceling your escrow
If the conditions aren't met, you can cancel the escrow with the EscrowCancel transaction type:
Learn more about escrow cancel
Use the escrow as a smart contract
You can use XRP Ledger escrows as smart contracts that release XRP after a certain time has passed or after a cryptographic condition has been fulfilled.
Last updated

