Ripple Quick Start Guide
eBook - ePub

Ripple Quick Start Guide

Get started with XRP and develop applications on Ripple's blockchain

  1. 160 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Ripple Quick Start Guide

Get started with XRP and develop applications on Ripple's blockchain

Book details
Book preview
Table of contents
Citations

About This Book

Learn to work with XRP and build applications on Ripple's blockchain

Key Features

  • Learn to use Ripple's decentralized system for transfering digital assets globally
  • A simpilfied and shortened learning curve to understand the Ripple innovation and Blockchain
  • Takes a hands-on approach to work with XRP – Ripple's native currency

Book Description

This book starts by giving you an understanding of the basics of blockchain and the Ripple protocol. You will then get some hands-on experience of working with XRP.

You will learn how to set up a Ripple wallet and see how seamlessly you can transfer money abroad. You will learn about different types of wallets through which you can store and transact XRP, along with the security precautions you need to take to keep your money safe.

Since Ripple is currency agnostic, it can enable the transfer of value in USD, EUR, and any other currency. You can even transfer digital assets using Ripple. You will see how you can pay an international merchant with their own native currency and how Ripple can exchange it on the fly. Once you understand the applications of Ripple, you will learn how to create a conditionally-held escrow using the Ripple API, and how to send and cash checks.

Finally, you will also understand the common misconceptions people have about Ripple and discover the potential risks you must consider before making investment decisions.

By the end of this book, you will have a solid foundation for working with Ripple's blockchain. Using it, you will be able to solve problems caused by traditional systems in your respective industry.

What you will learn

  • Understand the fundamentals of blockchain and Ripple
  • Learn how to choose a Ripple wallet
  • Set up a Ripple wallet to send and receive XRP
  • Learn how to protect your XRP
  • Understand the applications of Ripple
  • Learn how to work with the Ripple API
  • Learn how to build applications on check and escrow features of Ripple

Who this book is for

This book is for anyone interested in getting their hands on Ripple technology and learn where it can be used to gain competitive advantages in their respective fields. For most parts of the book, you need not have any pre-requisite knowledge. However, you need to have basic background of JavaScript to write an escrow.

Frequently asked questions

Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes, you can access Ripple Quick Start Guide by Febin John James in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming. We have over one million books available in our catalogue for you to explore.

Information

Year
2018
ISBN
9781789535969
Edition
1

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 the check later. You need to create another Ripple account from the Ripple test net faucet as we did earlier:
api.prepareCheckCreate(sender, {
"destination": receiver,
"sendMax": {
"currency": "XRP",
"value": "100"
}
}, options);
We would be using the following code to sign and submit the transaction to the network. It's the same methods we used to send money:
const {signedTransaction} = api.sign(prepared.txJSON, secret);
api.submit(signedTransaction).then(onSuccess,onFailure);
Once we submit the transaction to the network, we need to calculate the check ID. You need to communicate the check ID to the recipient so that they can use it to cash out the check. Here's the code to calculate check ID:
const checkIDhasher = createHash('sha512')
checkIDhasher.update(Buffer.from('0043', 'hex'))
checkIDhasher.update(new Buffer(decodeAddress(sender)))
const seqBuf = Buffer.alloc(4)
seqBuf.writeUInt32BE(message['tx_json']['Sequence'], 0)
checkIDhasher.update(seqBuf)
const checkID = checkIDhasher.digest('hex').slice(0,64).toUpperCase()
Let's put everything together:
'use strict';
const RippleAPI = require('ripple-lib').RippleAPI;
const decodeAddress = require('ripple-address-codec').decodeAddress;
const createHash = require('crypto').createHash;

const sender = 'r41sFTd4rftxY1VCn5ZDDipb4KaV5VLFy2';
const receiver = 'r42Qv8NwggeMWnpKcxMkx7qTtB23GYLHBX';
const secret = 'sptkAoSPzHq8mKLWrjU33EDj7v96u';
const options = {};

const api = new RippleAPI({server: 'wss://s.altnet.rippletest.net:51233'});
api.connect().then(() => {
console.log('Connected to the test network.');
return api.prepareCheckCreate(sender, {
"destination": receiver,
"sendMax": {
"currency": "XRP",
"value": "100"
}
}, options);

}).then(prepared => {
console.log("Transaction JSON:", prepared.txJSON);
const {signedTransaction} = api.sign(prepared.txJSON, secret);
console.log("Transaction Signed.")
api.submit(signedTransaction).then(onSuccess,onFailure);
});

function onSuccess(message){
console.log(message);
console.log("Transaction Successfully Submitted.");
const checkIDhasher = createHash('sha512');
checkIDhasher.update(Buffer.from('0043', 'hex'));
checkIDhasher.update(new Buffer(decodeAddress(sender)));
const seqBuf = Buffer.alloc(4);
seqBuf.writeUInt32BE(message['tx_json']['Sequence'], 0);
checkIDhasher.update(seqBuf);
const checkID = checkIDhasher.digest('hex').slice(0,64).toUpperCase();
console.log("CheckID:", checkID);
disconnect();
}

function onFailure(message){
console.log("Transaction Submission Failed.");
console.log(message);
disconnect();
}

function disconnect(){
api.disconnect().then(()=> {
console.log("Disconnected from test network.")
});
}
Save this as send_check.js. Let's execute the code by running the following command:
./node_modules/.bin/babel-node send_check.js
If everything goes fine, you'll get the following output:
Make a note of the check ID, as we'll be using it later in this chapter to cash the check. If you have noticed, no money has been deducted from our account. The money is only deducted when someone cashes the check.
Now, let's build a web app that allows users to log in and create checks.
In this app, we'll be using a few npm packages, hence we need browserify to compile these dependencies into one file. You can install browserify with the following command:
npm install -g browserify 
We would be using the same modal we used for sending money. In this application, we'll be separating the JavaScript to a different file, app.js, so that we can use browserify to get all of the dependencies to one file:
const RippleAPI = require('ripple-lib').RippleAPI;
const decodeAddress = require('ripple-address-codec').decodeAddress;
const createHash = require('crypto').createHash;

var api = new RippleAPI({server:'wss://s.altnet.rippletest.net:51233'});
var fetchBalance;
$('document').ready(function(){
login();
$('.progress').hide();
$('#sendCheckButton').click(function(){
showsendCheckModal();
});
$('#logoutButton').click(function(){
logout();
});
$("#loginButton").click(function(){
storeCredentials();
});
$("#createCheckButton").click(function(){
createCheck();
});
});

function login(){
if(!localStorage.getItem("loggedIn")){
$('#loginModal').modal('show');
} else{
updateAccount();
}
}

function logout(){
localStorage.clear();
clearInterval(fetchBalance);
location.reload();
}

function updateAccount(){
$('#rippleAddress').text(localStorage.getItem('rippleAddress'));
updateBalance();
}

function storeCredentials(){
localStorage.setItem("rippleAddress", $('#inputRippleAddress').val());
localStorage.setItem("secret", $('#inputSecret').val());
localStorage.setItem("loggedIn", true);
$('#loginModal').modal('hide');
updateAccount();
}

$("form").submit(function(e) {
e.preventDefault();
});

function updateBalance(){
api.connect().then(() => {
const accountAddress = localStorage.getItem("rippleAddress");
return api.getAccountInfo(accountAddress);
}).then(info => {
$('#balance').text("Account Balance : " + info.xrpBalance+ " XRP");
}).then(() => {
return api.disconnect();
}).catch(console.error);
}

function showsendCheckModal(){
$(...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. Dedication
  4. About Packt
  5. Contributors
  6. Preface
  7. Getting Started with Ripple
  8. Working with Ripple Currency XRP
  9. Applications of Ripple
  10. Getting Started with the Ripple API
  11. Developing Applications Using the Ripple API
  12. Other Books You May Enjoy