Ripple-lib を用いた基本的な動作を確認する。
●残高取得(getAccountInfo)
const RippleAPI = require('ripple-lib').RippleAPI;
 
const api = new RippleAPI({
  server: 'wss://s.altnet.rippletest.net:51233' // TestNet rippled server
});
 
run().catch(error => console.error(error.stack));
 
async function run() {
  await api.connect();
  const myAddress = 'rfQEB**************************';
  console.log('getting account info for', myAddress);
  const res = await api.getAccountInfo(myAddress);
  console.log('Done', res);
  process.exit(0);
}●トランザクション取得(getTransaction)
const RippleAPI = require('ripple-lib').RippleAPI;
const api = new RippleAPI({
  server: 'wss://s.altnet.rippletest.net:51233' // TestNet rippled server
});
run().catch(error => console.error(error.stack));
async function run() {
  await api.connect();
  const transactionid = '35EED****************************************************',
  console.log('getting transaction info for', transactionid);
  const res = await api.getTransaction(transactionid);
  console.log('Done', res);
  process.exit(0);
}●送金処理
const RippleAPI = require('ripple-lib').RippleAPI;
 
const api = new RippleAPI({
  server: 'wss://s.altnet.rippletest.net:51233' // TestNet rippled server
});
 
run().catch(error => console.error(error.stack));
 
async function run() {
 
  await api.connect();
  const myAddress = 'rfQEB**************************';
  const sendAddress = 'rhko3**************************'
  const secretkey = 'sso39**************************'
  
  const payment = {
    source: {
      address: myAddress,
      maxAmount: {
        value: '50.00',
        currency: 'XRP'
      }
    },
    destination: {
      address: sendAddress,
      amount: {
        value: '50.00',
        currency: 'XRP'
      }
    }
  };
  
  console.log('Get ready to submit the payment');
  const prepared = await api.preparePayment(myAddress, payment, {
    maxLedgerVersionOffset: 5
  });
  
  console.log('Sign the payment using the senders secret');
  const { signedTransaction } = api.sign(prepared.txJSON, secretkey);
  console.log('Signed', signedTransaction)
  
  // Submit the payment
  const res = await api.submit(signedTransaction);
  console.log('Done', res);
  process.exit(0);
}Ripple-libを用いることで、WEB、またはアプリケーションから残高照会やトランザクションの取得、送金などの機能を実装することが可能となります。
 CRYPTO LIFE