mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
Add sample API usage for getting balances and making a payment
This commit is contained in:
38
docs/samples/payment.js
Normal file
38
docs/samples/payment.js
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
const RippleAPI = require('../../src').RippleAPI; // require('ripple-lib')
|
||||
|
||||
const address = 'ENTER ADDRESS HERE';
|
||||
const secret = 'ENTER SECRET HERE';
|
||||
|
||||
const api = new RippleAPI({servers: ['wss://s1.ripple.com:443']});
|
||||
const instructions = {maxLedgerVersionOffset: 5};
|
||||
|
||||
const payment = {
|
||||
source: {
|
||||
address: address,
|
||||
amount: {
|
||||
value: '0.01',
|
||||
currency: 'XRP'
|
||||
}
|
||||
},
|
||||
destination: {
|
||||
address: 'rKmBGxocj9Abgy25J51Mk1iqFzW9aVF9Tc',
|
||||
amount: {
|
||||
value: '0.01',
|
||||
currency: 'XRP'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
api.connect(() => {
|
||||
console.log('Connected...');
|
||||
api.preparePayment(address, payment, instructions, (error, txJSON) => {
|
||||
console.log('Payment transaction prepared...');
|
||||
const signedTransaction = api.sign(txJSON, secret).signedTransaction;
|
||||
console.log('Payment transaction signed...');
|
||||
api.submit(signedTransaction, (submitError, response) => {
|
||||
console.log(submitError ? submitError : response);
|
||||
process.exit(submitError ? 1 : 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user