LoginSignup
4
1

More than 5 years have passed since last update.

Ripple (XRP) の残高を取得 (JavaScript)

Last updated at Posted at 2018-05-10
  • Ripple (XRP) の残高を取得する方法のメモです。
  • Ripple 公式のライブラリを使用します。
  • Ripple 公式ライブラリ ripple-lib: https://github.com/ripple/ripple-lib

ripple-lib のインストール

  • 公式では、yarn を推奨しているけど、以下は npm でインストールする例
$ npm install ripple-lib

コード例

  • getAccountInfo の返り値のオブジェクトが持っている xrpBalance を読みます。
const RippleAPI = require('ripple-lib').RippleAPI;

const api = new RippleAPI({
  server: 'wss://s1.ripple.com' // Public rippled server hosted by Ripple, Inc.
});

api.connect().then(() => {
    getXrpBalance('r39wDgtwjJkF5NAnXQhy3Z68dDboGebNJv');
}).then(() => {
  return api.disconnect();
}).catch(console.error);

function getXrpBalance(address) {
    api.getAccountInfo(address).then(info => {
        console.log(info.xrpBalance);
    });
};
4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1