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 =
... or in a browser:
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 = consoleconsole
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 hooks
Each Proxypay instance runs a series of functions called lifecycle hooks. These functions can be overridden to customise the behaviour of Proxypay:
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 instance attributes and methods
const payment = // Attributespaymentaddress // Address to fundpaymentfee // TX fee in satoshispaymenttotalSatoshis // Toal cost of tx in SatoshispaymentrequiredSatoshis // Remaining required Satoshispaymentbip21URI // Full bip21 URIpaymentisFunded // Boolean // Methodspayment // Opens websocket and listens for incoming UTXOpayment // Fetch all UTXO for the address // Both methods above fire `onFunded` when fundedpayment // Broadcast transaction // Fires either `onPayment` or `onError`payment // Sweep UTXO back to another address paymentpaymentpaymentpayment
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.