npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

smart-pockets

v0.1.0

Published

Downloads

4

Readme

Pockets

Pockets is a library for writing reccurring payment Smart Contracts on Ethereum.

Getting Started

Install truffle

npm install -g truffle
mkdir yourproject && cd yourproject
truffle init

To install the Pockets library, run:

npm init
npm install smart-pockets

or yarn

yarn init
yarn add smart-pockets

After that, you'll get the library's contracts in the node_modules/smart-pockets/contracts folder. You can use the contracts in the library like so:

import 'smart-pockets/contracts/PocketsHub';

contract SubscriptionHub is PocketsHub {
  ...
}

Developer Resources

  • Sample Project: https://github.com/zcstarr/pockets-sample

Project Overview

Organization

  • app/ - contains example application
    • setup.js - used to instantiate a pocket, registry, and service
      • server.js - a rest server that you can curl to access the service contract
            truffle migrate —reset 
            truffle console 
            Pockets.at(pocketAddress).then((pocket)=>pocket.registerService(serviceAddress, ‘CoolPlan’)); 
  • contracts/ - contains the contracts for Pockets
    • Pocket.sol - The pocket contract that holds a users eth
    • Service.sol - The service contract that holds a service providers eth
    • Registry.sol - A shared registry that allows pockets and service providers to trust that they’re running the proper smart contract code and have the same concept of time
    • PocketsHub.sol - The pocket and service factory to generate and deploy pocket and service contracts
  • test/ - Unit and integration tests for the Pockets/Service/PocketHub and Registry

Concepts

  • PocketsHub is a factory contract that takes an average block time and an Owner. It also deploys a public Registry that shows all the pockets and services registered with this hub. It is used to deploy new Service Contracts and Pocket Contracts

  • Registry is a contract that contains the registration for a Service, a service plan, and Pockets. This allows pockets and service providers to verify that they were produced by the hub and valid pocket/service contracts. Additionally it allows for service providers to communicate to pocket contracts what a subscription does.

  • Pockets is a contract that a user uses to register for service, or allow users to withdraw from a pocket on a one-shot or recurring basis

  • Service is a contract that a user uses to create a service to pull or accept users to gain access to services on a one-shot or recurring basis.

How's it work ?

The process works as follows

//A PocketHub is deployed with an 'initial average block time of 17 seconds'
PocketsHub.deployed().then((i)=> hub = i);

//The pockets hub contract deploys a registry. The hub owns this registry
hub.trustedRegistry.call().then((address) => {registry = Registry.at(address)});

// A service provider creates a new service 
hub.newService().then((tx)=> { service = Service.at(tx.logs[0].args.service)})

// The service provider owner registers a new plan
// The arguments are (serviceAddress, amount, frequency, initialDeposit, recurring, ’name’)
registry.registerPlan(service.address,web3.toWei(0.01,'ether'),34000,0,true,'CoolPlan')

//A user creates a pocket
hub.newPocket({from: web3.eth.accounts[1]}).then((tx) => pocket = Pockets.at(tx.logs[0].args.pocket));

// A user sends money to the pocket 
web3.eth.sendTransaction({from: web3.eth.accounts[3], value: web3.toWei(5,'ether') , to:pocket.address})


// The user signs up for the service;
pocket.registerService(service.address, 'CoolPlan');

// The service provider periodically checks its subscribers to see who they should collect from
// The service just places a hold on the subscription amount
service.requestHold(pocket.address)

// The service withdraws some amount from the pocket 
service.withdraw(pocket.address, web3.toWei(0.005,'ether'));

Up Next ?

Off chain state/payment channels

ERC-20 Token support

Wanna Help

Please contribute! Just create a PR or file an issue.

Special Thanks

Shout out to Eujern Lim for the PRs and discussions

License

Code released under the MIT License.