appino/blockchain

Blockchain API client library

v1.4.1 2020-11-20 10:54 UTC

This package is auto-updated.

Last update: 2024-03-20 18:50:02 UTC


README

Latest Version on Packagist Quality Score Total Downloads

An unofficial PHP library for interacting with the blockchain.info API.

Installation

In order to use this package you must provide an URL to an instance of service-my-wallet-v3. Before using these functionalities.service-my-wallet-v3.

You can install the package via composer:

composer require appino/blockchain

Add provider to app config

Appino\Blockchain\BlockchainServiceProvider::class

Publish Configuration File

php artisan vendor:publish --provider="Appino\blockchain\BlockchainServiceProvider"

Add 2 Lines to env File

blockchain_api_code=123456789abcdefghijklmnop //you must get api code from blockchain.info
blockchain_base_url=http://localhost:3000

Usage

Create

$blocchain = Blockchain::Create();

1. Creating Wallet

/**
 * @param string $password
 * @param string|null $email
 * @param string|null $label
 * @return WalletResponse
 * @throws ParameterError
 */
$blockchain->create($password, $email, $label);

2. Creating Wallet with specific private key

/**
 * @param string $password
 * @param string $privKey
 * @param string|null $email
 * @param string|null $label
 * @return WalletResponse
 * @throws ParameterError
 */
$blockchain->createWithKey($password, $privKey, $email, $label);

Wallet

$blockchain = Blockchain::Wallet();
$blockchain->credentials($guid, $password);

1. Create new Address

/**
 * @param null|string $label
 * @return AccountResponse
 */
$blockchain->CreateAddress($label));

2. Balance

/**
 * @return int in satoshi
 */ 
$blockchain->balnce();

3. Address Balance

/**
 * @param int|string $param can be index of address in wallet or address
 * @return int in satoshi
 */ 
$blockchain->AddressBallance($param);

4. Active Addresses

Return list of addresses of a Wallet

/**
 * @return array<AccountResponse>
 */ 
$blockchain->ActiveAddresses();

5. List of Xpubs

Return list of xpub

/**
 * @return array<string>
 */ 
$blockchain->XpubList();

6. Single Address Data

Return Single Address Data

/**
 * @param int|string $param can be index of address in wallet or address
 * @return AccountResponse
 */ 
$blockchain->SingleAddress($param);

7. Get Receiving Address

Return Receiving Address

/**
 * @param int|string $param can be index of address in wallet or address
 * @return string
 */ 
$blockchain->ReceivingAddress($param);

8. Archive Address

/**
 * @param int|string $param can be index of address in wallet or address
 * @return AccountResponse
 */ 
$blockchain->ArchiveAddress($param);

9. UnArchive Address

/**
 * @param int|string $param can be index of address in wallet or address
 * @return AccountResponse
 */ 
$blockchain->UnArchiveAddress($param);

10. Send Payment

/**
 * @param string $to bitcoin address that you want to send payment to
 * @param integer $amount amount of payment you want to send in satoshi
 * @param integer|string|null $from xpub address or index of account that you want to send payment from
 * @param int|null $fee 
 * @param int|null $fee_per_byte 
 * @return PaymentResponse
 * @throws ParameterError
 */
$blockchain->SendPayment($to, $amount, $from, $fee, $fee_per_byte);

11. Send Many Payment

/**
 * @param array<string,integer> $recipients recipients must be an array of address as key and satoshi as integer
 * @param integer|string|null $from xpub address or index of account that you want to send payment from
 * @param integer|null $fee must be in satoshi (better to set null or use fee_per_byte)
 * @param integer|null $fee_per_byte must be in satoshi
 * @return PaymentResponse
 * @throws ParameterError
 */
$blockchain->SendManyPayment($recipients, $from=null, $fee=null, $fee_per_byte = null);

Receive

$blocchain = Blockchain::Receive();

1. Generate Receiving Address

/**
 * @param string $xpub The public key.
 * @param string $callback The callback URL.
 * @param int $gap_limit How many unused addresses are allowed.
 * @return ReceiveResponse
 */
 $blockchain->Generate($xpub, $callback, $gap_limit = 20);

2. Get Address Gap

/**
 * @param $xpub string
 * @return int
 * @throws \GuzzleHttp\Exception\GuzzleException
 */
 $blockchain->AddressGap($xpub);

3. Balance Notification

/**
 * @param string $address
 * @param string $callback callback url
 * @param Notification|string $on what to do after notification called
 * @param int $confs how many confiramtion need to send notification
 * @param Operation|string $op on Receive/Send/All notification will send
 * @return NotificationResponse
 */
 $blockchain->BalanceNotification($address, $callback, $on, $confs, $op);

for deleting the notification use:

/**
 * @param $id int
 * @return bool
 * @throws \GuzzleHttp\Exception\GuzzleException
 */
 $blockchain->DeleteBalanceNotification($id);

4. Block Notification

/**
 * @param string $callback callback url
 * @param Notification|string $on what to do after notification called
 * @param int $confs how many confiramtion need to send notification
 * @param int|null $height height of block default(currentblock height  plus 1)
 * @return NotificationResponse
 * @throws \GuzzleHttp\Exception\GuzzleException
 */
 $blockchain->BlockNotification($callback, $on, $confs, $height);

for deleting the notification use:

/**
 * @param int $id
 * @return bool
 * @throws \GuzzleHttp\Exception\GuzzleException
 */
 $blockchain->DeleteBlockNotification($id);

5. Get CallBack Logs

/**
 * @param string $callback callback url
 * @return array<LogResponse>
 * @throws \GuzzleHttp\Exception\GuzzleException
 */
 $blockchain->CallbackLogs($callback);

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email cyberman9000@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.