Ripple Quick Start Guide
eBook - ePub

Ripple Quick Start Guide

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

Febin John James

Compartir libro
  1. 160 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Ripple Quick Start Guide

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

Febin John James

Detalles del libro
Vista previa del libro
Índice
Citas

Información del libro

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.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Ripple Quick Start Guide un PDF/ePUB en línea?
Sí, puedes acceder a Ripple Quick Start Guide de Febin John James en formato PDF o ePUB, así como a otros libros populares de Informatik y Programmierung. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2018
ISBN
9781789535969
Edición
1
Categoría
Informatik
Categoría
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(){
$(...

Índice