softinvest/laravel-bitgo-wallet

Bitgo blockchain service integration for laravel

dev-main 2022-06-11 14:50 UTC

This package is auto-updated.

Last update: 2024-12-11 20:22:54 UTC


README

You can install the package via composer:

composer require softinvest/laravel-bitgo-wallet

You can publish the config file with:

php artisan vendor:publish --provider="Khomeriki\BitgoWallet\BitgoServiceProvider"

This is the contents of the published config file:

return [
    'use_mocks' => env('BITGO_USE_MOCKS', true),//for tests

    'testnet' => env('BITGO_TESTNET', true),

    'api_key' => env('BITGO_API_KEY'),
    'v2_api_prefix' => 'api/v2/',
    'testnet_api_url'=>'https://app.bitgo-test.com',
    'mainnet_api_url'=>'https://app.bitgo.com',
    'express_api_url' => env('BITGO_EXPRESS_API_URL'),

    'default_coin' => env('BITGO_DEFAULT_COIN', 'tbtc'),
    'webhook_callback_url' => env('BITGO_WEBHOOK_CALLBACK'),
];

Usage

Generate a wallet with webhooks

use Khomeriki\BitgoWallet\Facades\Wallet;
$wallet = Wallet::init(coin: 'tbtc')
                ->generate(label: 'wallet label', passphrase: 'password')
                ->addWebhook(numConfirmations: 0)
                ->addWebhook(numConfirmations: 1);
                
return $wallet;

Add webhook on a wallet with custom callback url

use Khomeriki\BitgoWallet\Facades\Wallet;
$wallet = Wallet::init(coin: 'tbtc', id: 'wallet-id')
                ->addWebhook(
                    numConfirmations: 3, 
                    callbackUrl: 'https://your-domain.com/api/callback'
                );
                
return $wallet;

Generate address on an existing wallet

use Khomeriki\BitgoWallet\Facades\Wallet;

$wallet = Wallet::init(coin: 'tbtc', id: 'your-wallet-id')
                ->generateAddress(label: 'address label');
                
return $wallet->address;

Check maximum spendable amount on a wallet

use Khomeriki\BitgoWallet\Facades\Wallet;

$maxSpendable = Wallet::init(coin: 'tbtc', id: 'your-wallet-id')
                ->getMaximumSpendable();
                
return $maxSpendable;

Get all the transactions on wallet

use Khomeriki\BitgoWallet\Facades\Wallet;

$transfers = Wallet::init(coin: 'tbtc', id: 'your-wallet-id')
                ->getTransfers();
                
return $transfers;

Get transfer by transfer id

use Khomeriki\BitgoWallet\Facades\Wallet;

$transfer = Wallet::init(coin: 'tbtc', id: 'your-wallet-id')
                ->getTransfer(transferId: 'transferId');
                
return $transfer;

Send transfer from a wallet

use Khomeriki\BitgoWallet\Data\TransferRecipient;
use Khomeriki\BitgoWallet\Data\Transfer;
use Khomeriki\BitgoWallet\Facades\Wallet;

//you can add as many recipients as you need :)
$transfer = new Transfer(
    walletPassphrase: 'test',
    transferRecipients: [
        new TransferRecipient(amount: 4934, address: 'address'),
        new TransferRecipient(amount: 4334, address: 'address1'),
    ],
);
$result = Wallet::init('tbtc', 'wallet-id')->sendTransfer($transfer);

return $result;

Testing

composer test

Changelog

Credits

License

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