Ripple Quick Start Guide
eBook - ePub

Ripple Quick Start Guide

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

Febin John James

Partager le livre
  1. 160 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

Ripple Quick Start Guide

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

Febin John James

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

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.

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Ripple Quick Start Guide est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  Ripple Quick Start Guide par Febin John James en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Informatik et Programmierung. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2018
ISBN
9781789535969
Édition
1
Sous-sujet
Programmierung

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 des matiĂšres