Business-Bitcoin
view release on metacpan or search on metacpan
lib/Business/Bitcoin.pm view on Meta::CPAN
}
if ($auto =~ /^(xpub|path|db|version)$/x) {
return $self->{"\U$auto"};
}
else {
die "Could not AUTOLOAD method $auto.";
}
}
1; # End of Business::Bitcoin
__END__
=head1 NAME
Business::Bitcoin - Easy and secure way to accept Bitcoin payments online
=head1 VERSION
$Revision: 1.051 $
$Date: Tue Oct 16 22:26:58 PDT 2018 $
=head1 SYNOPSIS
An easy and secure way to accept Bitcoin payments online using an HD
wallet, generating new receiving addresses on demand and keeping the
wallet private key offline.
use Business::Bitcoin;
my $bizbtc = new Business::Bitcoin (DB => '/tmp/bizbtc.db',
XPUB => 'xpub...',
Create => 1);
my $req = $bizbtc->request(Amount => 4200);
print 'Please pay ' . $req->amount . ' Satoshi ' .
'to Bitcoin address ' . $req->address . ".\n" .
'Once the payment has ' . $req->confirmations , ' confirmations, ' .
"press <enter> to continue.\n";
readline(*STDIN);
print ($req->verify ? "Verified\n" : "Verification failed\n");
print "Enter a request address to verify a payment.\n";
my $address = <STDIN>; chomp $address;
my $req2 = $bizbtc->findreq(Address => $address);
print ($req2->verify ? "Verified\n" : "Verification failed\n");
=head1 HOW TO USE
To start receiving Bitcoin payments online, create an HD wallet using
a BIP-32 HD wallet app such as Electrum, get the Extended Public Key
for the wallet (a string beginning with "xpub") and plug it into the
constructor's XPUB argument.
Now you can receive online payments as outlined above, while keeping
your private key secure offline or in a hardware wallet. You should
take all precautions to ensure that your XPUB key on the server is
also safe, as its compromise can weaken your security, though it can't
in itself lead to the loss of any Bitcoin.
To make this work right you need to find the correct key to plug into
the XPUB parameter, so that the addresses generated by
Business::Bitcoin match those your wallet uses to receive payments.
If you're using the Electrum wallet, you can just use its Master
Public Key (from the menubar select Wallet -> Master Public Keys). To
use this key you must also set the 'Path' parameter to 'electrum' when
creating a new Business::Bitcoin object (or via the path() accessor).
By default, however, the addresses Business::Bitcoin generates will be
for the key derivation path k/i, where k is the path of the extended
public key provided in the XPUB parameter, and i is the index of the
address being generated.
This provides the flexibility to use Business::Bitcoin in conjunction
with any wallet, because different wallets use different key
derivation paths to generate addresses. e.g. Electrum uses the path
"m/0/i", MultiBit HD uses "m/a'/0/i", Mycellium uses
"m/44'/0'/a'/0/i", etc. (m is the "Master Public Key" and a is the
"account" index).
To have Business::Bitcoin generate addresses matching those generated
by your wallet, ensure that the XPUB parameter contains the public key
for the penultimate element of your wallet's key derivation path. So
for Electrum that would be m/0, for MultiBit HD m/a'/0, and for
Mycellium m/44'/0'/a'/0
Some wallets may not readily provide the key for this element of the
path. In that case you can find it using a tool such as "ku" from
Pycoin L<https://github.com/richardkiss/pycoin> or a JavaScript tool
such as the one at L<http://bip32.org/>. It's probably best never to
paste private keys in web forms however, so if your key derivation
path requires the private key, best to use something like the "ku"
tool on an offline machine.
=head1 METHODS
=head2 new
Create a new Business::Bitcoin object and open (or create) the
requests database. The following named arguments are required:
=over
DB - The filename of the requests database
XPUB - The extended public key for the wallet receiving payments
=back
The following optional named arguments can be provided:
=over
Create - Create the requests table if it doesn't exist. If the table
doesn't exist and Create is not true, the constructor will return
undef. Unset by default.
( run in 2.471 seconds using v1.01-cache-2.11-cpan-5735350b133 )