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

proxypay

v0.0.6

Published

Broadcast complex transactions to the Bitcoin SV blockchain from any wallet.

Downloads

26

Readme

Proxypay

Proxypay is a library for building complex transaction types which can be broadcasted to the Bitcoin SV blockchain by sending a simple payment from any wallet.

How is Proxypay different from Datapay?

Where the Datapay library requires the use of a private key already funded with a sufficient balance in order to broadcast the transaction, Proxypay excels when used with single-purpose, un-funded private keys.

Proxypay effectively creates an un-funded proxy transaction. Users can then fund the proxy transaction by sending a simple payment from their own wallet to the address of the private key, and as if by magic the proxy transaction will broadcast itself.

Why send transactions this way?

Proxypay allows BSV app developers to offer their users ways to fund complex and exotic transaction types from any wallet. It completely negates the need for Fat URI schemes as BIP21 URIs and QR codes can be used for all use cases.

This approach allows funding wallets to be kept completely separate. As we begin building for the Metanet, Proxypay enables developers to create Metanet node structures and address chains, without having to worry about complex UTXO management.

Getting started

Install Proxypay using npm or yarn:

npm install proxypay
# or
yarn add proxypay

Include Proxypay into your NodeJS or HTML project:

const proxypay = require('proxypay')

... or in a browser:

<script src="https://unpkg.com/proxypay/dist/proxypay.min.js"></script>

Note that Proxypay has a peer dependency on the bsv library which must also be available in your project.

Usage

Proxypay lets you build a transaction in a declarative manner. The config syntax is closer to Money Button's approach than Datapay's.

const payment = proxypay({
  key: 'L4vbW6A87f6VUUzRSCmthSvrr2AcAYntBUqorm45358QcAVvMGRe',
  outputs: [
    { data: ['testing', 'proxypay'] }
  ]
})
console.log(`Please send ${ payment.requiredSatoshis } satoshis to ${ payment.address }`)
console.log(payment.bip21URI)

The above example will wait for the correct fee to be sent to the private key's corresponding address (1PmbHb8d86FxaPmCtpHeFBCWebNimg8PcC), and once received will automatically broadcast the transaction.

Output syntax

The outputs configuration allows many outputs to be defined in a flexible manner:

proxypay({
  key: 'L4vbW6A87f6VUUzRSCmthSvrr2AcAYntBUqorm45358QcAVvMGRe',
  outputs: [
      // Simple payment outputs
    { to: address1, satoshis: 5000 },
    { to: address2, satoshis: 12000 },
    // Data array automatically compiled to OP_RETURN script
    { data: ['foo', 'bar', 'baz'] },
    // Raw bsv.Script instance
    { script: bsv.Script('...') },
  ]
}

Proxypay hooks

Each Proxypay instance runs a series of functions called lifecycle hooks. These functions can be overridden to customise the behaviour of Proxypay:

proxypay({
  key: 'L4vbW6A87f6VUUzRSCmthSvrr2AcAYntBUqorm45358QcAVvMGRe',
  outputs: [
    { data: ['testing', 'proxypay'] }
  ],
  // Default lifecycle hooks
  onCreate() { this.listen() },
  onFunded() { this.broadcast() },
  onPayment(tx) { console.log('Success', tx) },
  onError(err) { console.error('Error', err) }
}

For example, if you know the private key is already funded with sufficient balance, you can make Proxypay behave like Datapay and instantly broadcast the transaction by overriding the onCreate() method:

proxypay({
  key: 'L4vbW6A87f6VUUzRSCmthSvrr2AcAYntBUqorm45358QcAVvMGRe',
  outputs: [
    { data: ['testing', 'proxypay'] }
  ],
  onCreate() { this.getUtxo() }
}

Proxypay instance attributes and methods

const payment = proxypay(config)

// Attributes
payment.address           // Address to fund
payment.fee               // TX fee in satoshis
payment.totalSatoshis     // Toal cost of tx in Satoshis
payment.requiredSatoshis  // Remaining required Satoshis
payment.bip21URI          // Full bip21 URI
payment.isFunded          // Boolean

// Methods
payment.listen()        // Opens websocket and listens for incoming UTXO
payment.getUtxo()       // Fetch all UTXO for the address
                        // Both methods above fire `onFunded` when funded
payment.broadcast()     // Broadcast transaction
                        // Fires either `onPayment` or `onError`
payment.sweep(address)  // Sweep UTXO back to another address

payment.addInput(input)
payment.addOutput(output)
payment.estimateFee()
payment.closeSocket()

Design defensively

As Proxypay is handling users' money, and as it relies on third party services, developers should design systems defensively so that if anything goes wrong, users have a way to recover any funds.

The .getUtxo() and .sweep() functions are there for your benefit.

License

Proxypay is open source and released under the MIT License.

Copyright (c) 2019 libitx.