Escrow Tutorials

-

The XRP Ledger supports held payments, or escrows, that can be executed only after a certain time has passed or a cryptographic condition has been fulfilled. Escrows can only send XRP, not issued currencies. You can use these simple features to build publicly-provable smart contracts. This article explains basic tasks relating to held payments.

+

The XRP Ledger supports held payments, or escrows, that can be executed only after a certain time has passed or a cryptographic condition has been fulfilled. Escrows can only send XRP, not issued currencies. You can use these features to build publicly-provable smart contracts. This article explains basic tasks relating to held payments.

-

Take note of the transaction's identifying hash value so you can easily check its final status when it is included in a validated ledger version.

+

Take note of the transaction's identifying hash value so you can check its final status when it is included in a validated ledger version.

3. Wait for validation

On the live network or the Ripple Test Net, you can wait 4-7 seconds for the ledger to close automatically.

If you're running rippled in stand-alone mode, use the ledger_accept command to manually close the ledger.

@@ -397,7 +397,7 @@ console.log(release_date_ripple);

6. Submit EscrowFinish transaction

-

Sign and submit an EscrowCreate transaction to execute the release of the funds after the FinishAfter time has passed. Set the Owner field of the transaction to the Account address from the EscrowCreate transaction, and the OfferSequence to the Sequence number from the EscrowCreate transaction. For an escrow held only by time, omit the Condition and Fulfillment fields.

+

Sign and submit an EscrowFinish transaction to execute the release of the funds after the FinishAfter time has passed. Set the Owner field of the transaction to the Account address from the EscrowCreate transaction, and the OfferSequence to the Sequence number from the EscrowCreate transaction. For an escrow held only by time, omit the Condition and Fulfillment fields.

Tip: The EscrowFinish transaction is necessary because the XRP Ledger's state can only be modified by transactions. The sender of this transaction may be the recipient of the escrow, the original sender of the escrow, or any other XRP Ledger address.

Caution: Never submit a secret key to a server you do not control. Do not send a secret key unencrypted over the network.

Request:

@@ -443,7 +443,7 @@ console.log(release_date_ripple); } -

Take note of the transaction's identifying hash value so you can easily check its final status when it is included in a validated ledger version.

+

Take note of the transaction's identifying hash value so you can check its final status when it is included in a validated ledger version.

7. Wait for validation

On the live network or the Ripple Test Net, you can wait 4-7 seconds for the ledger to close automatically.

If you're running rippled in stand-alone mode, use the ledger_accept command to manually close the ledger.

@@ -558,9 +558,9 @@ console.log(release_date_ripple);

Send a conditionally-held escrow

1. Generate condition and fulfillment

-

XRP Ledger escrows require PREIMGE-SHA-256 Crypto-Conditions. To calculate a condition and fulfillment in the proper format, you should use a Crypto-Conditions library such as five-bells-condition. For fulfillments, Ripple recommends using one of the following methods to generate the fulfillment:

+

XRP Ledger escrows require PREIMAGE-SHA-256 Crypto-Conditions. To calculate a condition and fulfillment in the proper format, you should use a Crypto-Conditions library such as five-bells-condition. For fulfillments, Ripple recommends using one of the following methods to generate the fulfillment:

Example JavaScript code for a random fulfillment and condition:

@@ -574,26 +574,20 @@ console.log(myFulfillment.serializeBinary().toString('hex')); console.log(myFulfillment.getConditionBinary().toString('hex')); // (Random hexadecimal, 78 chars in length) -

Save the condition and the fulfillment for later. Be sure to keep the fulfillment secret until you want to finish executing the held payment; anyone who knows the fulfillment can finish the escrow, releasing the held funds to their intended destination.

+

Save the condition and the fulfillment for later. Be sure to keep the fulfillment secret until you want to finish executing the held payment. Anyone who knows the fulfillment can finish the escrow, releasing the held funds to their intended destination.

2. Calculate release or cancel time

A Conditional Escrow transaction must contain either a CancelAfter or FinishAfter field, or both. The CancelAfter field lets the XRP revert to the sender if the condition is not fulfilled before the specified time. The FinishAfter field specifies a time before which the escrow cannot execute, even if someone sends the correct fulfillment. Whichever field you provide, the time it specifies must be in the future.

Example for setting a CancelAfter time of 24 hours in the future:

-
+
const rippleOffset = 946684800;
 const CancelAfter = Math.floor(Date.now() / 1000) + (24*60*60) - rippleOffset;
 console.log(CancelAfter);
 // Example: 556927412
 
- -
from time import time
-ripple_offset = 946684800
-cancel_after = int(time()) + (24*60*60) - 946684800
-print(cancel_after)
-# Example: 556927412
-
+
-

Warning: In the XRP Ledger, you must specify time as seconds since the Ripple Epoch (2000-01-01T00:00:00Z). If you use a UNIX time in the CancelAfter or FinishAfter field without converting to the equivalent Ripple time first, that sets the unlock time to an extra 30 years in the future!

+

Warning: In the XRP Ledger, you must specify time as seconds since the Ripple Epoch (2000-01-01T00:00:00Z). If you use a UNIX time in the CancelAfter or FinishAfter field without converting to the equivalent Ripple time first, that sets the unlock time to an extra 30 years in the future!

3. Submit EscrowCreate transaction

Sign and submit an EscrowCreate transaction. Set the Condition field of the transaction to the time when the held payment should be released. Set the Destination to the recipient, which can be the same address as the sender. Include the CancelAfter or FinishAfter time you calculated in the previous step.

Caution: Never submit a secret key to a server you do not control. Do not send a secret key unencrypted over the network.

@@ -745,7 +739,7 @@ print(cancel_after)

6. Submit EscrowFinish transaction

-

Sign and submit an EscrowCreate transaction to execute the release of the funds after the FinishAfter time has passed. Set the Owner field of the transaction to the Account address from the EscrowCreate transaction, and the OfferSequence to the Sequence number from the EscrowCreate transaction. Set the Condition and Fulfillment fields to the condition and fulfillment values, in hexadecimal, that you generated in step 1. Set the Fee (transaction cost) value based on the size of the fulfillment in bytes: a conditional EscrowFinish requires at least 330 drops of XRP plus 10 drops per 16 bytes in the size of the fulfillment.

+

Sign and submit an EscrowFinish transaction to execute the release of the funds after the FinishAfter time has passed. Set the Owner field of the transaction to the Account address from the EscrowCreate transaction, and the OfferSequence to the Sequence number from the EscrowCreate transaction. Set the Condition and Fulfillment fields to the condition and fulfillment values, in hexadecimal, that you generated in step 1. Set the Fee (transaction cost) value based on the size of the fulfillment in bytes: a conditional EscrowFinish requires at least 330 drops of XRP plus 10 drops per 16 bytes in the size of the fulfillment.

Note: If you included a FinishAfter field in the EscrowCreate transaction, you cannot execute it before that time has passed, even if you provide the correct fulfillment for the Escrow's condition. The EscrowFinish transaction fails with the result code tecNO_PERMISSION if the previously-closed ledger's close time is before the FinishAfter time.

Caution: Never submit a secret key to a server you do not control. Do not send a secret key unencrypted over the network.

@@ -795,7 +789,7 @@ print(cancel_after) }
-

Take note of the transaction's identifying hash value so you can easily check its final status when it is included in a validated ledger version.

+

Take note of the transaction's identifying hash value so you can check its final status when it is included in a validated ledger version.

7. Wait for validation

On the live network or the Ripple Test Net, you can wait 4-7 seconds for the ledger to close automatically.

If you're running rippled in stand-alone mode, use the ledger_accept command to manually close the ledger.