Created
July 12, 2018 17:56
-
-
Save stevenbg/17dbb5ae7e6573becab28ce1afefb49c to your computer and use it in GitHub Desktop.
XRP wallet for coders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| '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