blocktrail / blocktrail-sdk
The BlockTrail PHP SDK, for integration of Bitcoin functionality through the BlockTrail API
Installs: 21 093
Dependents: 3
Suggesters: 0
Security: 0
Stars: 44
Watchers: 8
Forks: 49
Open Issues: 37
Requires
- php-64bit: >=5.6.0
- ext-bcmath: *
- ext-curl: *
- ext-dom: *
- ext-gd: *
- ext-gmp: *
- ext-intl: *
- 99designs/http-signatures-guzzlehttp: 2.0.*
- bitwasp/bitcoin: v0.0.34.1
- blocktrail/cryptojs-aes-php: 0.1.*
- btccom/cashaddress: v0.0.3
- btccom/justencrypt: v0.2.0
- dompdf/dompdf: 0.6.*
- endroid/qrcode: 1.5.*
- guzzlehttp/guzzle: 6.*
- mdanter/ecc: v0.4.*
- ramsey/array_column: ~1.1
- rych/hash_pbkdf2-compat: ~1.0
- spomky-labs/php-aes-gcm: v1.2.0
Requires (Dev)
- php-coveralls/php-coveralls: ^1.0
- phpunit/phpunit: 4.3.*
- squizlabs/php_codesniffer: 2.*
- dev-master
- v3.2.3
- v3.2.2
- v3.2.1
- v3.2.0
- v3.1.10
- v3.1.9
- v3.1.8
- v3.1.7
- v3.1.6
- v3.1.5
- v3.1.4
- v3.1.3
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v1.3.11
- v1.3.10
- v1.3.9
- v1.3.8
- v1.3.7
- v1.3.6
- v1.3.5
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.x-dev
- v1.2.21
- v1.2.20
- v1.2.19
- v1.2.18
- v1.2.17
- v1.2.16
- v1.2.15
- v1.2.14
- v1.2.13
- v1.2.12
- v1.2.11
- v1.2.10
- v1.2.9
- v1.2.8
- v1.2.7
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.0
- 1.0.4
- 1.0.3
- 1.0.1
- 1.0.0
- 0.1.1
- dev-btc35-2
- dev-require-activation
- dev-tk-test-refactoring
- dev-test-refactoring
- dev-curl-issues
- dev-btc-35
- dev-fork-blocktrail-backend
- dev-2fatoken
- dev-remove-discovery
- dev-release-script
- dev-cash-address-try-with-prefix
- dev-handle-topublic-as-if-immutable
- dev-network-instance
- dev-high-priority-feerate
- dev-v3-backup-scenarios
- dev-size-estimation-data-test
- dev-unit-test-sdk
- dev-release-v1.x
- dev-release-v2.x
- dev-input-dont-sign
- dev-txbuilder
- dev-bcc
- dev-bcc-replay-protection
- dev-split-up-test-files
- dev-regtest
- dev-rbf
- dev-debug1
- dev-release-v2.1.1
- dev-release-v2.1.0
- dev-wallet-path-from-bip32
- dev-wallet-path-from-bip39path
- dev-tmp-ruben
- dev-wallets-v2b
- dev-cli-tool
- dev-development
- dev-wallet-webhook
- dev-release-v1.2.1
This package is auto-updated.
Last update: 2024-10-09 14:22:32 UTC
README
This is the BlockTrail PHP SDK. This SDK contains methods for easily interacting with the BlockTrail API. Below are examples to get you started. For additional examples, please see our official documentation at https://dev.btc.com/docs/php
Upgrading from v2.x to v3.0.0
IMPORTANT v3.0.0
introduces a new DEFAULT wallet encryption, please make sure you upgrade the SDK everywhere you're using it!!
Upgrading from v1.x to v2.0.0
IMPORTANT v2.0.0
has a few BC breaks, please check docs/CHANGELOG.md!!
Upgrading from v1.2.x to v1.3.0
IMPORTANT v1.3.0
adds the option to choose a fee strategy and by default chooses DYNAMIC, please check docs/CHANGELOG.md for the details!!
IMPORTANT! FLOATS ARE EVIL!!
As is best practice with financial data, The API returns all values as an integer, the Bitcoin value in Satoshi's. In PHP even more than in other languages it's really easy to make mistakes whem converting from float to integer etc!
When doing so it's really important that you use the bcmath
or gmp
libraries to avoid weird rounding errors!
The BlockTrail SDK has some easy to use functions to do this for you, we recommend using these
and we also strongly recommend doing all Bitcoin calculation and storing of data in integers
and only convert to/from Bitcoin float values for displaying it to the user.
use Blocktrail\SDK\BlocktrailSDK; echo "123456789 Satoshi to BTC: " . BlocktrailSDK::toBTC(123456789) . " \n"; echo "1.23456789 BTC to Satoshi: " . BlocktrailSDK::toSatoshi(1.23456789) . " \n";
A bit more about this can be found in our documentation.
Requirements
The SDK requires PHP 5.6+ and the Intl, GMP and BCMath PHP extensions.
To install these on Ubuntu use:
sudo apt-get install php5-bcmath php5-intl php5-gmp
sudo php5enmod mcrypt
BCMath should already be part of the default php5 package
On Windows you need to uncomment the extensions in your php.ini
if they are not already enabled:
extension=php_intl.dll
extension=php_gmp.dll
Installation
To install the SDK, you will need to be using Composer in your project. If you aren't using Composer yet, it's really simple! Here's how to install composer and the BlockTrail PHP SDK.
# Install Composer
curl -sS https://getcomposer.org/installer | php
# Add the BlockTrail SDK as a dependency
php composer.phar require blocktrail/blocktrail-sdk
Next, require Composer's autoloader, in your application, to automatically load the BlockTrail SDK in your project:
require 'vendor/autoload.php'; use Blocktrail\SDK\BlocktrailSDK;
Or if put the following in your composer.json
:
"blocktrail/blocktrail-sdk": "1.2.*"
Windows Developers
A note for windows developers: you may encounter an issue in php with cURL and SSL certificates, where cURL is unable to verify a server's cert with a CA ((error 60)[http://curl.haxx.se/libcurl/c/libcurl-errors.html]).
Too often the suggested solution is to disable ssl cert verification in cURL, but this completely defeats the point of using SSL. Instead you should take two very simple steps to solve the issue permanently:
- download
cacert.pem
from the curl website. This is a bundle of trusted CA root certs extracted from mozilla.org. Save it in a folder within your php installation. - open your
php.ini
and add/edit the following line (use an absolute path to where you placed the cert bundle):
curl.cainfo = C:\php\certs\cacert.pem
(Optional) Use libsecp256k1
The underlying bitcoin-php
library that is used to sign transactions can use libsecp256k1
for (A LOT) faster signing of transactions.
If the secp256k1-php
PHP extension is installed it will be automatically used and will greatly improve performance!
The installation is a bit cumbersome though and because libsecp256k1
still changes a lot building might not always work!
If you can get it to install; AWESOME, if not, have patience while we're working on figuring out how to provide installers for them.
https://github.com/Bit-Wasp/secp256k1-php#to-install
MAKE SURE TO RUN THE TESTSUITE OF secp256k1-php
AFTER THE INSTALL BEFORE ENABLING THE EXTENSION!!
Usage
Please visit our official documentation at https://dev.btc.com/docs/php for the usage.
Support and Feedback
Be sure to visit the BlockTrail API official documentation website for additional information about our API.
If you find a bug, please submit the issue in Github directly. BlockTrail-PHP-SDK Issues
If you need additional assistance, contact one of our developers at support@btc.com.
Unit Tests and Coding Style
The project follows the PSR2 coding style, which can easily be validated with ./vendor/bin/phpcs --standard=./phpcs.xml -n -a ./src/
.
Unit Tests are created with PHPunit and can be ran with ./vendor/bin/phpunit
Release
# make sure you've committed everything? git status # desired new tag TAG="v1.1.1" # strips off the v from your input TAG=$(echo $TAG | sed 's/^v//g') # update version number in src/Blocktrail.php sed -i 's/const SDK_VERSION = "[0-9].[0-9].[0-9]";/const SDK_VERSION = "'$TAG'";/g' src/Blocktrail.php # commit the updated version number git commit -am "release v${TAG}" # tag the version git tag v$TAG # push git push git push --tags
License
The BlockTrail PHP SDK is released under the terms of the MIT license. See LICENCE.md for more information or see http://opensource.org/licenses/MIT.