PHP code example of neto737 / bitgosdk-php

1. Go to this page and download the library: Download neto737/bitgosdk-php 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/ */

    

neto737 / bitgosdk-php example snippets


use neto737\BitGoSDK\BitGoExpress;
use neto737\BitGoSDK\BitGoSDK;
use neto737\BitGoSDK\Enum\CurrencyCode;

// Calls that don't need your keys go straight to BitGo. The third argument selects testnet.
$bitgo = new BitGoSDK('YOUR_ACCESS_TOKEN', CurrencyCode::BITCOIN_TESTNET, true);
$bitgo->walletId = 'YOUR_WALLET_ID';

$wallet = $bitgo->getWallet();              // ['id' => '...', 'label' => '...', 'balanceString' => '...', ...]
$address = $bitgo->createWalletAddress();   // ['address' => '2N...', 'chain' => 10, ...]

// Sending needs an unlocked session. The OTP is always 000000 on testnet.
$unlock = $bitgo->unlockSession('000000');
if (isset($unlock['error'])) {
    exit($unlock['error']);
}

// Anything that signs goes through your BitGo Express instance
$express = new BitGoExpress('localhost', 3080, CurrencyCode::BITCOIN_TESTNET);
$express->accessToken = 'YOUR_ACCESS_TOKEN';
$express->walletId = 'YOUR_WALLET_ID';

$amount = BitGoSDK::toSatoshi('0.001');     // 100000. Pass BTC amounts as strings to avoid float rounding.
$tx = $express->sendTransaction('DESTINATION_ADDRESS', $amount, 'YOUR_WALLET_PASSPHRASE');

$transfer = $bitgo->getWalletTransfer('TRANSFER_ID');

if (isset($transfer['error'])) {
    if ($transfer['status'] === 0) {
        // no response: timeout, DNS, TLS, ...
    } elseif ($transfer['status'] === 404) {
        // no such transfer
    } else {
        // any other non-2xx status, or an invalid JSON body
    }
}

$express = new BitGoExpress('https://express.internal', 3080, CurrencyCode::BITCOIN);

// For a self-signed or private-CA certificate, trust that certificate or CA file.
$express->setCaFile('/path/to/express.crt');

$bitgo->setTimeout(30);          // request timeout in seconds. Default: 60 (BitGoSDK) or 310 (BitGoExpress)
$bitgo->setConnectTimeout(5);    // connect timeout in seconds. Default: 10
$bitgo->setForceIPv4(true);      // use IPv4 only. Default: whatever the system allows
$bitgo->setCaFile('/path/to/ca.pem');