PHP code example of mrbeandev / coinbase-cdp

1. Go to this page and download the library: Download mrbeandev/coinbase-cdp 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/ */

    

mrbeandev / coinbase-cdp example snippets


use MrBeanDev\CoinbaseCDP\CoinbaseCDP;

$cb = new CoinbaseCDP(
    orgId:      'your-org-uuid',
    apiKeyId:   'your-api-key-uuid',
    privateKey: file_get_contents('cdp_key.pem'),
);

// List accounts
$accounts = $cb->accounts()->list();

// Get BTC balance
$btc = $cb->accounts()->get('BTC');
echo $btc['data']['balance']['amount'];

// Create a deposit address
$address = $cb->addresses()->create($accountId, 'User deposit');
echo $address['data']['address'];

// Send crypto
$tx = $cb->transactions()->send(
    accountId: $accountId,
    to:        '0xabc123...',
    amount:    '0.01',
    currency:  'ETH',
);

// Poll for incoming deposits
$deposits = $cb->transactions()->confirmedDeposits($accountId);

$cb->accounts()->list($limit, $startingAfter)   // paginated list
$cb->accounts()->get($idOrCurrency)              // by UUID or "BTC"
$cb->accounts()->getByCurrency('ETH')            // shortcut
$cb->accounts()->all()                           // auto-paginate all

$cb->addresses()->create($accountId, $name, $network)  // new deposit address
$cb->addresses()->list($accountId)                      // list addresses
$cb->addresses()->get($accountId, $addressId)           // single address
$cb->addresses()->transactions($accountId, $addressId)  // txs for address

$cb->transactions()->list($accountId, $limit, $order)           // list all
$cb->transactions()->get($accountId, $txId)                     // single tx
$cb->transactions()->send($accountId, $to, $amount, $currency)  // send crypto
$cb->transactions()->transfer($from, $to, $amount, $currency)   // internal
$cb->transactions()->deposits($accountId, $limit, $status)      // filter receives
$cb->transactions()->confirmedDeposits($accountId)               // completed only

use MrBeanDev\CoinbaseCDP\Exception\CoinbaseException;

try {
    $cb->transactions()->send(...);
} catch (CoinbaseException $e) {
    echo $e->getMessage();       // human-readable error
    print_r($e->getResponseBody()); // raw API response
}