0.2.0 • Published 4 years ago

bandi-events v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Overview

This library is part of the Bandi group of projects. These are meant to encourage and incentivize users to enter into the Web Monetization ecosystem. These projects provide a set of tools to help easily bootstrap a rewards framework for a website or application.

Bandi-Events sets up listeners to monitor transaction events. You can set a custom multiplier to reward users with points based on their contributions. Take the following example:

  • User has 0 points
  • Creator has set a multiplier of 100x
  • User streams 0.01 to creator
  • Bandi-Events captures transaction event and uses multiplier to determine points accrued: 0.01 * 100 = 1 point
  • User balance is updated to 1 and the new balance is returned through callback

Bandi will always be unopinionated about how you use & manage points, and will stay decoupled from any specific systems implementation. It's simply a set of tools intended to help creators bootstrap a rewards system for their applications.

Requirements

Check out the official Web Monetization Quick Start Guide to learn how to set up a wallet for receiving payments. This library assumes you have a meta tag to set up monetization with the payment pointer to your wallet. Example:

<meta
  name="monetization"
  content="$wallet.example.com/alice"
>

Installation

npm install bandi-events --save

or

yarn add bandi-events

Example

const events = new BandiEvents();

events.init({
  currentBalance: 0,
  multiplier: 1000,
  onTransaction: (tx) => console.log(tx),
});

Parameters

NameTypeRequiredDescription
currentBalancenumberyesThe current point balance for a user.
multipliernumberyesA multiplier for adjusting how many points each transaction will convert to.
onTransactionfunctionnoAn optional callback function that triggers on each transaction.

API

NameReturnsDescription
initvoidInitialize a new BandiEvents instance.
getCurrentBalancenumberReturns the user's current point balance.
startMonetizationvoidStarts the monetization event listener (called automatically with init).
stopMonetizationvoidStops the monetization event listener (called automatically with cleanup).
isActivebooleanReturns whether a BandiEvents instance has been initialized.

Contributing

If you've noticed a bug or have a feature you'd like to suggest, feel free to open a GitHub Issue. If you would like to contribute to the project, feel free to fork this repo, create a new branch & open a pull request.

Licence

MIT © brewsterbhg