Giter Club home page Giter Club logo

rippled's Introduction

rippled


https://github.com/ripple/rippled/

xrp ledger

https://xrpl.org/get-started-with-rippleapi-for-javascript.html#first-rippleapi-script

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

const api = new RippleAPI({
  server: 'wss://s1.ripple.com'
});
api.connect().then(() => {
  const myAddress = 'xxx';
  
  console.log('getting account info for', myAddress);
  return api.getAccountInfo(myAddress);
}).then(info => {
  console.log(info);
  console.log('getAccountInfo done');
}).then(info => {
  return api.disconnect();
}).then(
  console.log('done and disconnected');
).catch(console.error);


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

const myAddr = 'xxx';
const mySecret = 'xxx';

const myOrder = {
  'direction': 'buy',
  'quantity': {
    'currency': 'FOO',
    'couterparty': 'xxx',
    'value': '100'
  },
  'totalPrice': {
    'currency': 'XRP',
    'value': '1000'
  }
};

const INTERVAL = 1000;
const api = new RippleAPI({server: 'wss://s2.ripple.com'});
const ledgerOffset = 5;
const myInstructions = {maxLedgerVersionOffset: ledgerOffset};

function verifyTransaction(hash, options) {
  console.log('Verifying Trasaction');
  return api.getTransaction().then(data => {
    console.log('Final Result: ', data.outcome.result);
    console.log('Validated in Ledger: ', data.outcome.ledgerVersion);
    console.log('Sequence: ', data.sequence);
    return data.outcome.result === 'tesSUCCESS';
  }).catch(error => {
    if (error instanceof api.errors.PendingLedgerVersionError) {
      return new Promise((resolve, reject) => {
        setTimeout(() => verifyTransaction(hash, options)
        .then(resolve, reject), INTERVAL);
      });
    }
    return error;
  });
}

function submitTransaction(lastClosedLedgerVersion, prepared, secret) {
  const signeData = api.sign(prepared.txJSON, secret);
  return api.submit(signedData.signedTransaction).then(data => {
    minLedgerVersion: lastClosedLedgerVersion,
    maxLedgerVersion: prepared.instructions.maxLedgerVersion
  });
  return new Promise((resolve, reject) => {
    setTimeout(() => verifyTransaction(signedData.id, options)
  .then(resolve, reject), INTERVAL);
  });
}

api.connection().then(() => {
  console.log('Connected');
  return api.prepareOrder(myAddr, myOrder, myInstructions);
}).then(prepared => {
  console.log('Order Prepared');
  return api.getLedger().then(ledger => {
    console.log('Current Ledger', ledger.ledgerVersion);
    return submitTransaction(ledger.ledgerVersion, prepared, mySecret);
  });
}).then(() => {
  api.disconnect().then(() => {
    console.log('api disconnected');
    process.exit();
  });
}).catch(console.error);
node --version
nodejs --version
yarn --version
mkdir my_ripple_experiment 99 cd my_ripple_experiment
git init
yarn
node get-account-info.js
{
  "name": "my_ripple_experiment",
  "version": "0.0.1",
  "license": "MIT",
  "private": true,
  "//": "Change the license to something appropriate. You may want to use 'UNLICENSED' if your are just starting out.",
  "dependencies": {
    "ripple-lib": "*"
  },
  "devDependencies": {
    "eslint": "*"
  }
}

rippled's People

Contributors

takagotch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.