Pockets
Pockets is a library for writing reccurring payment Smart Contracts on Ethereum.
Getting Started
Install truffle
npm install -g trufflemkdir yourproject && cd yourprojecttruffle init
To install the Pockets library, run:
npm initnpm 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:
; 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 —resettruffle consolePockets.at.then((pocket)=>pocket.registerService(serviceAddress, ‘CoolPlan’));
- setup.js - used to instantiate a pocket, registry, and service
- 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; //The pockets hub contract deploys a registry. The hub owns this registryhubtrustedRegistry; // A service provider creates a new service hub // The service provider owner registers a new plan// The arguments are (serviceAddress, amount, frequency, initialDeposit, recurring, ’name’)registry //A user creates a pockethub; // A user sends money to the pocket web3eth // The user signs up for the service;pocket; // The service provider periodically checks its subscribers to see who they should collect from// The service just places a hold on the subscription amountservice // The service withdraws some amount from the pocket service;
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.