Skip to content

Instantly share code, notes, and snippets.

@stevenbg
Created July 12, 2018 17:56
Show Gist options
  • Select an option

  • Save stevenbg/17dbb5ae7e6573becab28ce1afefb49c to your computer and use it in GitHub Desktop.

Select an option

Save stevenbg/17dbb5ae7e6573becab28ce1afefb49c to your computer and use it in GitHub Desktop.
XRP wallet for coders
// get account info (balance)
'use strict';
const RippleAPI = require('ripple-lib').RippleAPI;
const api = new RippleAPI({
server: 'wss://s1.ripple.com' // Public rippled server
});
api.connect().then(() => {
// set your address
const myAddress = '';
console.log('getting account info for', myAddress);
return api.getAccountInfo(myAddress);
}).then(info => {
console.log(info);
}).then(() => {
return api.disconnect();
}).then(() => {
console.log('done and disconnected.');
}).catch(console.error);
// assign a regular key pair to your account
'use strict';
const RippleAPI = require('ripple-lib').RippleAPI;
const api = new RippleAPI({
server: 'wss://s1.ripple.com' // Public rippled server
});
// min fee is 0.00001 XRP (10 drops)
const txJSON = JSON.stringify({
"Flags": 0,
"TransactionType": "SetRegularKey",
"Account": "", // your address
"Fee": "10", // specified in drops!
"Sequence": 1, // has to match the current value for your address (from account-info.js)
"RegularKey": "" // the desired address (public key) to add
})
const secret = '';
const signResult = api.sign(txJSON, secret);
api.connect().then(() => {
return api.submit(signResult.signedTransaction);
}).then(info => {
console.log(info);
}).then(() => {
return api.disconnect();
}).then(() => {
console.log('done and disconnected.');
}).catch(console.error);
// generates a key pair
var keypairs = require('ripple-keypairs');
var seed = (process.argv.length==3) ? process.argv[2] : keypairs.generateSeed();
var keypair = keypairs.deriveKeypair(seed);
console.log("Ripple-address: " + keypairs.deriveAddress(keypair.publicKey));
console.log("Ripple-secret: " + seed);
'use strict';
const RippleAPI = require('ripple-lib').RippleAPI;
const api = new RippleAPI({
server: 'wss://s1.ripple.com' // Public rippled server
});
const txJSON = JSON.stringify({
"Flags": 0,
"Fee": "10", // min fee is 0.00001 XRP (10 drops)
"Sequence": 1, // has to match the current value for your address (from account-info.js)
"Account": "", // set your address
"TransactionType": "Payment",
"Destination": "", // set destination address
"DestinationTag": 0, // set a tag if you need to
"Amount" : "1000000" // in drops! -> 1 XRP = 1000000 drops
});
// set your secret
const secret = '';
const signResult = api.sign(txJSON, secret);
api.connect().then(() => {
return api.submit(signResult.signedTransaction);
}).then(info => {
console.log(info);
}).then(() => {
return api.disconnect();
}).then(() => {
console.log('done and disconnected.');
}).catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment