PHP code example of redberryproducts / laravel-crypto-wallet

1. Go to this page and download the library: Download redberryproducts/laravel-crypto-wallet library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

redberryproducts / laravel-crypto-wallet example snippets


return [
    'drivers' => [
        'bitgo' => [
            'use_mocks' => env('BITGO_USE_MOCKS', false),
            'testnet' => env('BITGO_TESTNET', true),
            'api_key' => env('BITGO_API_KEY'),
            'express_api_url' => env('BITGO_EXPRESS_API_URL'),
            'default_coin' => env('BITGO_DEFAULT_COIN', 'tbtc4'),//This is not a typo or just a result of a lazy developer :). BitGo is moving to Testnet4, so the Bitcoin testnet is now TBTC4.
            'webhook_callback_url' => env('BITGO_WEBHOOK_CALLBACK'),
        ],
    ],
];


use RedberryProducts\CryptoWallet\WalletManager;

$wallet = WalletManager::bitgo();

$wallet = WalletManager::bitgo(coin: 'tbtc', walletId: 'my-wallet-id');

$wallet = WalletManager::bitgo(coin: 'tbtc')
    ->generate(
        label: 'Test Wallet',
        passphrase: 'test-passphrase',
        enterpriseId: 'enterprise-id',
    );

$wallet = WalletManager::bitgo(coin: 'tbtc', walletId: 'wallet-id')
        ->get();

$wallets = WalletManager::bitgo()->listAll();

$address = WalletManager::bitgo(coin: 'tbtc', walletId: 'wallet-id')
    ->generateAddress(label: 'My Address');

$transfers = WalletManager::bitgo(coin: 'tbtc', walletId: 'wallet-id')
    ->getTransfers();

use RedberryProducts\CryptoWallet\Drivers\Bitgo\Data\SendTransferToMany\SendToManyRequest;
use RedberryProducts\CryptoWallet\Drivers\Bitgo\Data\SendTransferToMany\Recipient;

$sendTransferData = new SendToManyRequest(
    recipients: [
        new Recipient(address: 'tb1psv9q9zlp94s9jncnlye4kj0acyp56suxf28hn4k34vyrmsrp4qtsc9eqlq', amount: 4368),
    ],

    walletPassphrase: 'test',
    feeRate: 250,
);

$response = WalletManager::bitgo(coin: 'tbtc', walletId: 'wallet-id')
    ->sendTransferToMany(sendToManyRequest: $sendTransferData);

$maxSpendable = WalletManager::bitgo(coin: 'tbtc', walletId: 'wallet-id')
    ->getMaximumSpendable([
        'feeRate' => 0,
    ]);

$result = WalletManager::bitgo(coin: 'tbtc', walletId: 'wallet-id')->consolidate([
    'walletPassphrase' => 'testing-pass',
    'bulk' => true,
    'minValue' => '0',
    'minHeight' => 0,
    'minConfirms' => 0,
]);

$webhook = WalletManager::bitgo('tbtc')
    ->generate(
        label: 'wallet with webhook', 
        passphrase: 'test-passphrase',
        enterpriseId: 'enterprise-id'
    )
    ->addWebhook(
        numConfirmations: 6, 
        callbackUrl: 'https://yourapp.com/webhook/bitgo'
    );


use RedberryProducts\CryptoWallet\ExchangeRateManager;

$rates = ExchangeRateManager::bitgo()->all();

use RedberryProducts\CryptoWallet\ExchangeRateManager;

$tbtcRates = ExchangeRateManager::bitgo()->getByCoin('tbtc');