LoginSignup
0
1

More than 5 years have passed since last update.

ripple-libからrippledに接続する手順

Last updated at Posted at 2017-05-14

バッチなどで都度接続するやり方です

npmインストール

npm i ripple-lib

nodejs6

チュートリアルにのっているがこんな感じ

'use strict';
const RippleAPI = require('ripple-lib').RippleAPI;

const ripple_main = (api) => {
    return api.getLedger().then(res => res.ledgerVersion).then(current_ledger => {
        // 行いたい処理
    })
}

const main = () => {
    const api = new RippleAPI({server: 'wss://s1.ripple.com:443'});
    api.on('connected', () => {
        console.log('Connection is open now.');
    });
    api.on('disconnected', (code) => {
        if (code !== 1000) {
            console.log('Connection is closed due to error.');
        } else {
            console.log('Connection is closed normally.');
        }
    });
    return api.connect().then(() => ripple_main(api) ).
        then(() => api.disconnect() ).
        then(() => process.exit(0)).
        catch(console.error);
}

main()

nodejs7

async / await版

'use strict';
const RippleAPI = require('ripple-lib').RippleAPI;

const ripple_main = async (api) => {
    const current_ledger = await api.getLedger().then(res => res.ledgerVersion)
    // 行いたい処理
}

const main = async () => {
    const api = new RippleAPI({server: 'wss://s1.ripple.com:443'});
    api.on('connected', () => {
        console.log('Connection is open now.');
    });
    api.on('disconnected', (code) => {
        if (code !== 1000) {
            console.log('Connection is closed due to error.');
        } else {
            console.log('Connection is closed normally.');
        }
    });
    await api.connect()
    await ripple_main(api)
    await api.disconnect()
    return process.exit(0)
}

main().catch(console.error)

ps

process.exit(0)入れないと接続が切れないことがある
公式のチュートリアルにもあるんだよな
この問題昔からあった気がする
https://github.com/you21979/node-ripple-trade-helper/issues/8
これに関連? http://qiita.com/you21979@github/items/cad9f5f6fa77e9d36107

0
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
0
1