GithubHelp home page GithubHelp logo

cj0910 / whisper-payment-channel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from blockequity/whisper-payment-channel

0.0 0.0 0.0 17 KB

Sample payment channel using whisper

JavaScript 100.00%

whisper-payment-channel's Introduction

Whisper payment channels

Payment channels using whisper

This "DApp" is missing all frontend stuff. Simple open a geth client and load in the test.js file. Make sure you deploy the contract and set the correct contract address in payment_channel.js (this will change!)

Dox

Setting up payer:

// create a new payment channel on the payer side
var tx = new PaymentChannel({
    account: eth.accounts[0],  // set eth account
    me: sender,                // my whisper id
    them: receiver,            // their whisper id
    role: PaymentChannel.payer,
    payment: {
        value: web3.toWei(2, "ether"), // value for the payment channel
        base: web3.toWei(1, "ether"),  // base cost
        inc: 100000,                   // incremental amount
    },
});
tx.onPayload = function(payload) {
    return true; // keep paying the beneficiary
};

Setting up beneficiary:

var rx = new PaymentChannel({
    account: eth.accounts[1],   // set eth account (to which the payment goes on the eth network)
    me: receiver,               // my whisper id
    them: sender,               // their whisper id
    role: PaymentChannel.beneficiary,
    payment: {
        base: web3.toWei(1, "ether"), // min accepted base fee
        inc: 100000,                  // min accepted inc fee
    },
});
// set payment callback
rx.onPayment = function(error, payment) {
    if( error ) {
        console.log("invalid payment:", error);
        return false;
    }
    return true; // keep accepting more more payments for more data
};
rx.data = myDataFunction; // some data function which returns data (false == done)

Fire them up:

tx.start();
rx.start();

whisper-payment-channel's People

Contributors

obscuren 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.