Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
var express = require('express');
var fs = require('fs');
var app = express();
// generate a wallet. The smart-wallet manages this wallet, and the user can only control it via the smart-wallet.
// The wallet is bound to the rules of the 'resilience network'. It will automatically send dividends based on the rate that the user has set.
var RippleWallet = require('ripple-wallet')
var wallet = RippleWallet.generate();
// generate a key for the owner of this smart-wallet
var ResilienceKey = require('resilience-key-generator')
var res_key = ResilienceKey.generate();
// return the key to the process that booted up the smart-contract
// ...
// set dividendRate
var dividendRate = "" // import value from the process that booted up the smart-wallet
// container for dividendPathways
var dividendPathways = []
// subscribe to transactions for this wallet
var WebSocket = require('ws')
var websocket = new WebSocket('wss://')
var subscribeCommand = '{"command":"subscribe","id":0,"accounts":["'+wallet.address+'"]}'
websocket.on('open', function(){
console.log('Connected to the Ripple payment network')
websocket.on('message', function(data){
console.log('message', data)
// do this stuff,
// the smart-wallet will perform a somewhat complex algorithm, and communicate with other smart-wallets within the 'resilience network',
// and distribute dividends based on some somewhat complex rules
// for more info, read about my swarm-redistribution algorithm on
// connect to Ripple
var RippleRestClient = require("ripple-rest-client").Client;
var client = new RippleRestClient({
api: '',
account: wallet.address,
secret: wallet.secret
// provide some control to the user who has the smart-wallet's key (not the key to the wallet - the wallet can only be known by the contract - the contract's wallet is controlled by another key)'/sendpayment/', function (req, res) {
//first, verify cryptographic signature to gain access to the smart-wallet
if(req.body.resilience_secret_key === res_key){
//then send payment
recipient: req.body.destination,
amount: req.body.amount,
currency: req.body.currency,
issuer: wallet.address
}, function(err, response){
console.log('payment submitted');
});'/editDividendRate/', function (req, res) {
dividendRate = req.body.dividendRate
// define more:
// ...
// ...
app.get('/', function(req, res) {
// let the user check stuff
app.listen(process.env.PORT || 8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment