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

databutton

v0.0.5

Published

A Datapay plugin to build Moneybutton

Downloads

25

Readme

Databutton

A Datapay plugin to build Moneybutton

code

Install

Include 3 scripts, in the following order:

<script src="https://www.moneybutton.com/moneybutton.js"></script>
<script src='https://unpkg.com/datapay'></script>
<script src='https://unpkg.com/databutton'></script>

Usage

You can use Datapay to upload the following types to the blockchain:

  1. ASCII String
  2. Hex String
  3. Binary

1. ASCII & Hex String

Similar to datapay syntax, except that the pay part is replaced with button.

databutton.build({
  data: ["0x6d02", "hello world"],
  button: { $el: document.querySelector("#button") }
})

The button.$el can either be:

  • an element
  • selector

For example, you can use the selector notation instead of passing an element:

databutton.build({
  data: ["0x6d02", "hello world"],
  button: { $el: "#button" }
})

2. Binary & String

You can upload not just string but also files in raw binary format. For this, we introduce a new attribute called file. We use this instead of data.

The file attribute contains two child attributes:

  • $el: the selector for the input[type=file] element. Databutton will listen to a file selection event, and will create a moneybutton.
  • data: the same data attribute as ordinary datapay "data" payload, with a twist. You have access to 2 root level variables:
    • databutton.file: The ArrayBuffer formatted file which you can directly feed into the blockchain.
    • databutton.type: The file content type (image/png, video/mp4, etc.) as specified in https://www.iana.org/assignments/media-types/media-types.xhtml
    • databutton.name: The file name
    • databutton.lastModified: The lastModified attribute
    • databutton.lastModifiedDate: The lastModifiedDate attribute
    • databutton.size: The file size

Here's an example databutton code for building a B:// protocol upload:

databutton.build({
  file: {
    $el: document.querySelector("#file"),
    data: [
      "19HxigV4QyBv3tHpQVcUEQyq1pzZVdoAut",
      databutton.file,
      databutton.type,
      "binary",
      databutton.name
    ]
  },
  button: {
    $el: document.querySelector("#button")
  }
})

Or, you can simply use the selectors

databutton.build({
  file: {
    $el: "#file",
    data: [
      "19HxigV4QyBv3tHpQVcUEQyq1pzZVdoAut",
      databutton.file,
      databutton.type,
      "binary",
      databutton.name
    ]
  },
  button: {
    $el: "#button"
  }
})

Advanced

1. Send Moneybutton attributes

You can pass additional Moneybutton parameters to databutton's button object:

databutton.build({
  data: ["0x6d02", "hello world"],
  button: {
    $el: "#button",
    label: "swipe",
    to: [address],
    amount: "1",
    currency: "USD",
    onPayment: function(msg) {
      console.log(msg)
    }
  }
})

2. Add money transfer options

You can also specify additional pay attribute to send money. This is possible through the $pay attribute.

Currently $pay only has only one attribute: to, which is equivalent to datapay's "pay.to" attribute usage.

Here's an example:

databutton.build({
  data: ["0x6d0c", "topic", "hello world"],
  button: {
    $el: "#button",
    $pay: {
      to: [{
        address: "qq4kp3w3yhhvy4gm4jgeza4vus8vpxgrwc90n8rhxe",
        value: 100000
      }]
    }
  }
})