Skip to content

Instantly share code, notes, and snippets.

@bitgord
Created December 12, 2016 02:58
Show Gist options
  • Save bitgord/b7f615af9eae303a29a680e14819020a to your computer and use it in GitHub Desktop.
Save bitgord/b7f615af9eae303a29a680e14819020a to your computer and use it in GitHub Desktop.
Quick Setup of Ripple Lib with Nodejs to Query the Ripple API
// Node must be downloaded to beign
// Install ripple-lib // A JavaScript API for interacting with Ripple in Node.js and the browser
npm install ripple-lib
// In Node require ripple-lib
const {RippleAPI} = require('ripple-lib');
// The object that is returned contains all the functionality to query the ripple network
// First you must connect to Ripples servers // Run this from node terminal
const api = new RippleAPI({
server: 'wss://s1.ripple.com' // Public rippled server hosted by Ripple, Inc.
});
api.on('error', (errorCode, errorMessage) => {
console.log(errorCode + ': ' + errorMessage);
});
api.on('connected', () => {
console.log('connected');
});
api.on('disconnected', (code) => {
// code - [close code](https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent) sent by the server
// will be 1000 if this was normal closure
console.log('disconnected, code:', code);
});
api.connect().then(() => {
/* insert code here */
}).then(() => {
return api.disconnect();
}).catch(console.error);
// Your terminal should return that you are now connected to Ripple
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment