Ethereum payment api for Dazaar stream services
const PaymentETH = require('dazaar-payment-eth')
const market = require('dazaar/market')
const hypercore = require('hypercore')
const m = market('./tmp')
const feed = hypercore('./tmp/data')
const opts = {
feedKey: 'de..adbeef', // feed key for the ethereum index
}
const paymentCard = {
ethPubKey: '0x50c7d91e74b0e42bd8bce8ad6d199e4a23c0b193',
id: 'dazaartest22'
currency: 'microether',
amount: '1',
unit: 'seconds',
interval: 1
}
let payment
// instantiate a seller for a feed and equip it
// with a validate function
const seller = m.sell(feed, {
validate (remoteKey, cb) {
payee.validate(remoteKey, cb)
}
})
seller.ready(function (err) {
// payment now set up. dazaar logic follows ...
payment = new PaymentETH(seller, paymentCard, opts)
})
// instantiate a buyer for a specific feed
const buyer = m.buy(seller.key)
// generate the ethereum adress to pay to for a given stream
const payTo = PaymentETH.tweak(buyer.key, opts)
// pay the desired amount to the address generated
Create a new eth payment instance associated to a seller. seller
should be a dazaar seller instance, payment
may either be a dazaar payment card, or a string specifying the per second rate in either ETH
, such as 0.0002 ETH/s
. Options include:
{
feedKey: ..., // feed key for a remote ethereum index
client: ..., // client for the remote index service (see https://github.com/hyperdivision/eth-indexer-service)
index: ..., // alternatively, a live indexer instance may also be passed in
endpoint: ..., // specify an chain endpoint and an new index shall be made
}
A seller can validate the time left for a given buyer. Returns error
if there is no time left on the subscription. The method shall check whether the given buyer has a subscription set-up and instantiate one not already present.
Static method to generate the ETH address to pay to for a given stream. buyerKey
is the buyer's dazaar key and dazaarCard
give the relevant stream details.
MIT