1. Go to this page and download the library: Download farzin-dev/coinbase 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/ */
farzin-dev / coinbase example snippets
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
// with a refresh token
$configuration = Configuration::oauth($accessToken, $refreshToken);
// without a refresh token
$configuration = Configuration::oauth($accessToken);
$client = Client::create($configuration);
use Coinbase\Wallet\Enum\Param;
use Coinbase\Wallet\Exception\TwoFactorRequiredException;
use Coinbase\Wallet\Resource\Transaction;
$transaction = Transaction::send([
'toEmail' => '[email protected]',
'bitcoinAmount' => 1
]);
$account = $client->getPrimaryAccount();
try {
$client->createAccountTransaction($account, $transaction);
} catch (TwoFactorRequiredException $e) {
// show 2FA dialog to user and collect 2FA token
// retry call with token
$client->createAccountTransaction($account, $transaction, [
Param::TWO_FACTOR_TOKEN => '123456',
]);
}
$transactions = $client->getAccountTransactions($account);
while ($transactions->hasNextPage()) {
$client->loadNextTransactions($transactions);
}
use Coinbase\Wallet\Enum\Param;
$transactions = $client->getAccountTransactions($account, [
Param::FETCH_ALL => true,
]);
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$configuration->setLogger($logger);
$client = Client::create($configuration);
use Coinbase\Wallet\Resource\Deposit;
use Coinbase\Wallet\Resource\PaymentMethod;
$deposit = new Deposit([
'paymentMethod' => PaymentMethod::reference($paymentMethodId)
]);
// or use the convenience method
$deposit = new Deposit([
'paymentMethodId' => $paymentMethodId
]);
$data = $deposit->getRawData();
$data = $client->decodeLastResponse();
$client->enableActiveRecord();
use Coinbase\Wallet\Enum\Param;
$transactions = $account->getTransactions([
Param::FETCH_ALL => true,
]);
use Coinbase\Wallet\Enum\CurrencyCode;
use Coinbase\Wallet\Resource\Transaction;
use Coinbase\Wallet\Value\Money;
$transaction = Transaction::send([
'toBitcoinAddress' => 'ADDRESS',
'amount' => new Money(5, CurrencyCode::USD),
'description' => 'Your first bitcoin!',
'fee' => '0.0001' // only
use Coinbase\Wallet\Resource\Transaction;
use Coinbase\Wallet\Resource\Account;
$fromAccount = Account::reference($accountId);
$toAccount = new Account([
'name' => 'New Account'
]);
$client->createAccount($toAccount);
$transaction = Transaction::transfer([
'to' => $toAccount,
'bitcoinAmount' => 1,
'description' => 'Your first bitcoin!'
]);
$client->createAccountTransaction($fromAccount, $transaction);
use Coinbase\Wallet\Enum\CurrencyCode;
use Coinbase\Wallet\Resource\Transaction;
use Coinbase\Wallet\Value\Money;
$transaction = Transaction::request([
'amount' => new Money(8, CurrencyCode::USD),
'description' => 'Burrito'
]);
$client->createAccountTransaction($transaction);
$account->resendTransaction($transaction);
$account->cancelTransaction($transaction);
$account->completeTransaction($transaction);
$buys = $client->getAccountBuys($account);
$buy = $client->getAccountBuy($account, $buyId);
use Coinbase\Wallet\Resource\Buy;
$buy = new Buy([
'bitcoinAmount' => 1
]);
$client->createAccountBuy($account, $buy);
use Coinbase\Wallet\Enum\Param;
$client->createAccountBuy($account, $buy, [Param::COMMIT => false]);
$client->commitBuy($buy);
use Coinbase\Wallet\Enum\CurrencyCode;
use Coinbase\Wallet\Resource\Deposit;
use Coinbase\Wallet\Value\Money;
$deposit = new Deposit([
'amount' => new Money(10, CurrencyCode::USD)
]);
$client->createAccountDeposit($account, $deposit);
use Coinbase\Wallet\Enum\Param;
$client->createAccountDeposit($account, $deposit, [Param::COMMIT => false]);
$client->commitDeposit($deposit);
use Coinbase\Wallet\Enum\CurrencyCode;
use Coinbase\Wallet\Resource\Withdrawal;
use Coinbase\Wallet\Value\Money;
$withdrawal = new Withdrawal([
'amount' => new Money(10, CurrencyCode::USD)
]);
$client->createAccountWithdrawal($account, $withdrawal);
use Coinbase\Wallet\Enum\Param;
$client->createAccountWithdrawal($account, $withdrawal, [Param::COMMIT => false]);
$client->commitWithdrawal($withdrawal);