We prepare the transaction by defining the structure as per the specification mentioned in Ripple API's documentation. We define the source address, destination address, amount, currency type, and so on. The "preparePayment" function that follows inputs the data to prepare a standard JSON that can be signed and submitted to the network:
'use strict';
const RippleAPI = require('ripple-lib').RippleAPI;
const api = new RippleAPI({
server: 'wss://s.altnet.rippletest.net:51233' // Ripple Test Network Address
});
const instructions = {};
const sourceAddress = 'r41sFTd4rftxY1VCn5ZDDipb4KaV5VLFy2';
const sourceSecret = 'sptkAoSPzHq8mKLWrjU33EDj7v96u';
const destinationAddress = 'rMLhQ61cGQ3kcsGMFugYJV9QjP31BiMXav'
const amount = '50';
const instructions = {};
const transaction = {
source: {
address: sourceAddress,
maxAmount: {
value: amount,
currency: 'XRP'
}},
destination: {
address: destinationAddress,
amount: {
value: amount,
currency: 'XRP'
}}};
api.preparePayment(sourceAddress, transaction, instructions);