Skip to content

Instantly share code, notes, and snippets.

@wilsonianb
Created February 22, 2017 15:28
Show Gist options
  • Save wilsonianb/14b98f78998e3dcd425c6140cb5177e5 to your computer and use it in GitHub Desktop.
Save wilsonianb/14b98f78998e3dcd425c6140cb5177e5 to your computer and use it in GitHub Desktop.
var ripple = require('./dist/npm/index.js')
var Promise = require('bluebird')
var _ = require('lodash')
const ADDRESS = process.env['RIPPLE_ADDRESS']
const SECRET = process.env['RIPPLE_SECRET']
const DEST = process.env['DESTINATION_ADDRESS']
const IP = process.env['RIPPLE_SERVER']
const PUBKEY = process.env['PUBLIC_KEY']
class PayChan {
constructor(options) {
this.destination = options.destination,
this.amount = options.amount,
this.settleDelay = options.settleDelay,
this.publicKey = options.publicKey
}
submit(remote, address, secret) {
return remote.preparePaymentChannelCreate(address, this).then(prepared => {
const {signedTransaction} = remote.sign(prepared.txJSON, secret);
remote.submit(signedTransaction);
});
}
}
const api = new ripple.RippleAPI({server: IP});
api.connect().then(() => {
return new PayChan({
address: ADDRESS,
destination: DEST,
amount: '20',
settleDelay: 10000,
publicKey: PUBKEY
})
.submit(api, ADDRESS, SECRET).then(result => {
console.log(result)
})
.catch(error => {
console.log(error)
})
}).catch(error => {
console.log(error)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment