Reader small image

You're reading from  Ripple Quick Start Guide

Product typeBook
Published inDec 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781789532197
Edition1st Edition
Languages
Right arrow
Author (1)
Febin John James
Febin John James
author image
Febin John James

Febin John James is presently working on building autonomous lending and borrowing protocol on the Ethereum blockchain. He also works as a tech and marketing consultant to ICOs and blockchain-based start-ups. He has years of experience in building and scaling tech architectures from scratch. His blockchain stories on Medium have gained a lot of popularity and have been translated into multiple languages. He writes for well-known publications such as Hacker Noon and freeCodeCamp. He is also the author of the book, Cloud is a Piece of Cake. Previously, he worked as the CTO of Boutline, a sports start-up. He has also bagged devices, cash prizes, and recognition from companies such as Intel, Blackberry, and Microsoft.
Read more about Febin John James

Right arrow

Developing Applications Using the Ripple API

In the previous chapter, we learned to use the Ripple API to send money into a Ripple account. In this chapter, we'll learn to use the check and Escrow features of Ripple to make banking applications.

In this chapter, we'll cover the following topics:

  • Sending checks
  • Cashing checks
  • Creating and releasing a time-held escrow
  • Creating and releasing a conditionally-held escrow

Sending checks

Now, let's learn how to send checks from a Ripple account. In order to send checks, we need to accomplish the following three things. The process is similar to sending money:

  1. Prepare transaction: Here we define the destination address, amount to be paid, and so on.
  2. Sign transaction: You need to sign the transaction cryptographically with your secret key. This proves that you own this account.
  3. Submit transaction: Once you sign the transaction, you need to submit it to the Ripple network for validation. Your check would become valid only when the validators approve your transaction.

In order to create a check, we would be using the "CheckCreate" method. The following code takes the destination and amount to be paid as input and generates the transaction JSON as output. You need to own the recipient account since we would be using it to cash out...

Cashing checks

You should be familiar with the process by now. It's similar to sending money and creating checks. In order to cash a check, you need to have the check ID created by the sender using the following steps:

  1. Prepare transaction: Here we define the check ID, amount to be cashed out, and so on.
  2. Sign transaction: You need to sign the transaction cryptographically with your secret key. This proves that you own this account.
  3. Submit transaction: Once you sign the transaction, you need to submit it to the Ripple network for validation. The check will be cashed out and the account balance will only be updated when the validators approve your transaction.

The following code uses the "CheckCash" method to prepare the transaction. The sign and submit method are similar to the one we used before. We have used the check ID that we noted down earlier. You&apos...

Creating a time-held escrow

We'll again go with the same step of steps as before to create a time-held escrow:

  1. Prepare transaction: Here, we define the destination account to which money should be released, escrow release time, amount, and so on.
  2. Sign transaction: You need to sign the transaction cryptographically with your secret key. This proves that you own the source account.
  3. Submit transaction: Once you sign the transaction, you need to submit it to the Ripple network for validation. The escrow would be only created when the validators approve the transaction.

We prepare the create escrow transaction with the following code. As you can see, we've defined the destination and amount and passed the release time to "allowExecuteAfter" parameter:

const sender = 'r41sFTd4rftxY1VCn5ZDDipb4KaV5VLFy2';
const secret = 'sptkAoSPzHq8mKLWrjU33EDj7v96u...

Creating a conditionally-held escrow

Conditionally-held escrows are similar to time-held escrows. However, you need to send the condition and the fulfillment after the release time for the escrow to be released. Ripple makes use of crypto conditions. For the purpose of this tutorial, we'll be generating a random fulfillment and condition. You need to keep the fulfillment secret, otherwise, anyone with the fulfillment code will be able to release the escrow.

Let's generate a random fulfillment and condition. You'll need to install the five-bells-condition npm library. You can do that using the following command:

npm install five-bells-condition 

Use the following code to generate a random fulfillment and condition:

const cc = require('five-bells-condition')
const crypto = require('crypto')

const preimageData = crypto.randomBytes(32);
const myFulfillment...

Important things you must remember

Following are some important points that you must when on Ripple:

  • Most transactions on Ripple follow the three-step process of preparing the transaction, signing it, and submitting it.
  • Transactions are applied only when validators approve the transaction.
  • When a check is created on Ripple, no money is deducted until it's cashed out.
  • Escrow in Ripple doesn't support issues currencies. It only supports XRP.
  • Time-held escrows in Ripple can be released by anyone only after the release time is passed. However, the money is released only to the destination account specified by the sender.
  • A conditionally-held escrow needs the condition and fulfillment to be passed in order to release the locked funds.

Summary

In this chapter, we learned the following things:

  • How to cash a check
  • How to create and release a time-held escrow
  • How to create and release a conditionally-held escrow
  • How to build a user interface by integrating Ripple APIs into a web app

Now, that you're familiar with Ripple APIs, please have a look at the Ripple Developer Docs. It would give you access to more functionalities. You'll also be updated when new features are added. You can also follow the Ripple community on Reddit.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Ripple Quick Start Guide
Published in: Dec 2018Publisher: PacktISBN-13: 9781789532197
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Febin John James

Febin John James is presently working on building autonomous lending and borrowing protocol on the Ethereum blockchain. He also works as a tech and marketing consultant to ICOs and blockchain-based start-ups. He has years of experience in building and scaling tech architectures from scratch. His blockchain stories on Medium have gained a lot of popularity and have been translated into multiple languages. He writes for well-known publications such as Hacker Noon and freeCodeCamp. He is also the author of the book, Cloud is a Piece of Cake. Previously, he worked as the CTO of Boutline, a sports start-up. He has also bagged devices, cash prizes, and recognition from companies such as Intel, Blackberry, and Microsoft.
Read more about Febin John James