Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ Entries for 2.2.3 and earlier were reconstructed from the git history in October

## [Unreleased]

### Added

- `Wallet::update()` changes a wallet's label, `approvalsRequired`, `disableTransactionNotifications`, `buildDefaults` and `coinSpecific` settings, and returns the updated wallet.
- `Wallet::freeze()` blocks every send from the wallet for `duration` seconds, one hour by default, with an optional `reason` and `referenceId`.
- `Wallet::maximumSpendable()` returns the most the wallet can send in one transaction. The UTXO filters (`minValue`, `maxValue`, `minConfirms`, `feeRate`, `unspentIds`…) are named params, and `minValue` and `maxValue` take an `Amount`.
- `$coin->wallets()->balances()` adds up the balances of your wallets of one coin (`/api/v2/{coin}/wallet/balances`).
- `$bitgo->wallets()` covers every coin at once: `list()` pages through all your wallets (`/api/v2/wallets`), filtered by coin, enterprise, type or label, and `balances()` returns the totals per coin (`/api/v2/wallet/balances`). The `coin` filter takes `CoinCode`s or strings.

## [3.0.0-alpha.1] - 2026-10-30

The first pre-release of 3.0, a new client written from scratch. It covers addresses, wallets and webhooks, and its API may still change before 3.0.0. It can't send coins yet: BitGo Express, transfers and sending come in the 3.0 betas, so stay on 2.3.x for production. 2.x fixes continue on the `2.x` branch.
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ With Symfony HttpClient, pass `new Psr18Client(HttpClient::create(['timeout' =>

| From | Methods |
| --- | --- |
| `$bitgo` | `coin($code)`, `lastResponse()` |
| `$bitgo` | `coin($code)`, `wallets()`, `lastResponse()` |
| `$bitgo->wallets()` (every coin) | `list()`, `balances()` |
| `$bitgo->coin('tbtc')` | `wallet($id)`, `wallets()`, `blockWebhooks()` |
| `->wallets()` | `list()`, `findByAddress($address)` |
| `->wallet($id)` | `get()`, `addresses()`, `webhooks()` |
| `->wallets()` (coin) | `list()`, `findByAddress($address)`, `balances()` |
| `->wallet($id)` | `get()`, `update()`, `freeze()`, `maximumSpendable()`, `addresses()`, `webhooks()` |
| `->addresses()` | `create()`, `get()`, `update()`, `list()`, `deploy()`, `forwardTokens()`, `getOwnershipProof()` |
| `->webhooks()` (wallet) | `add()`, `list()`, `remove()`, `simulate()` |
| `->blockWebhooks()` (coin) | `add()`, `list()`, `remove()`, `simulate()` |
Expand Down
8 changes: 8 additions & 0 deletions src/BitGo.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ public function coin(CoinCode|string $coin): Coin
return new Coin($this->http, $coin);
}

/**
* Your wallets of every coin, to list them or add up their balances. Sends no request.
*/
public function wallets(): Wallets
{
return new Wallets($this->http);
}

/**
* The HTTP response to the latest request this client sent, for its status and headers. Verbs return only the
* decoded body, so read this right after the call.
Expand Down
30 changes: 30 additions & 0 deletions src/Coin/Wallets.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,36 @@ public function findByAddress(string $address, array $extra = []): array
return $wallet;
}

/**
* The total balances of your wallets of this coin, added up. Amounts are strings in base units.
*
* For every coin at once, use BitGo::wallets()->balances().
*
* @param bool|null $allTokens Include the totals of the coin's tokens, keyed by token code under 'tokens'
* @param list<string>|null $enterprise Only wallets in these enterprises, by ID
* @param bool|null $showAllWallets Also count deleted wallets and wallets whose creation failed
* @param bool|null $includeStakingBalances Also return the staked and reward totals
* @param array<string, mixed> $extra More query params, for ones this method doesn't name yet
* @return array{balanceString: string, confirmedBalanceString: string, spendableBalanceString: string, stakedBalanceString?: string, tokens?: array<string, array{balanceString: string, confirmedBalanceString: string, spendableBalanceString: string, ...}>, ...}
* @throws BitGoException
*/
public function balances(
?bool $allTokens = null,
?array $enterprise = null,
?bool $showAllWallets = null,
?bool $includeStakingBalances = null,
array $extra = [],
): array {
/** @var array{balanceString: string, confirmedBalanceString: string, spendableBalanceString: string, stakedBalanceString?: string, tokens?: array<string, array{balanceString: string, confirmedBalanceString: string, spendableBalanceString: string, ...}>, ...} $balances BitGo's documented shape, not checked at runtime */
$balances = $this->http->get('{coin}/wallet/balances', $this->path(), [
'allTokens' => $allTokens,
'enterprise' => $enterprise,
'showAllWallets' => $showAllWallets,
'includeStakingBalances' => $includeStakingBalances,
], $extra);
return $balances;
}

/**
* @return array{coin: string}
*/
Expand Down
100 changes: 100 additions & 0 deletions src/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,106 @@ public function get(?bool $allTokens = null, array $extra = []): array
return $wallet;
}

/**
* Update the wallet's settings. Only the params you pass are changed.
*
* @param string|null $label A new name for the wallet
* @param int|null $approvalsRequired How many admins must approve a pending approval, 1 or more
* @param bool|null $disableTransactionNotifications Stop BitGo's emails about the wallet's transactions
* @param array<string, mixed>|null $buildDefaults UTXO coins: defaults for building transactions, such as 'feeMultiplier', 'changeAddressType' or 'txFormat'
* @param array<string, mixed>|null $coinSpecific Settings for one coin, keyed by its code, for example ['teth' => ['deployForwardersManually' => true]]
* @param array<string, mixed> $extra More body params, for ones this method doesn't name yet
* @return array{id: string, coin: string, label: string, balanceString?: string, confirmedBalanceString?: string, spendableBalanceString?: string, ...}
* @throws BitGoException
*/
public function update(
?string $label = null,
?int $approvalsRequired = null,
?bool $disableTransactionNotifications = null,
?array $buildDefaults = null,
?array $coinSpecific = null,
array $extra = [],
): array {
/** @var array{id: string, coin: string, label: string, balanceString?: string, confirmedBalanceString?: string, spendableBalanceString?: string, ...} $wallet BitGo's documented shape, not checked at runtime */
$wallet = $this->http->put('{coin}/wallet/{walletId}', $this->path(), [
'label' => $label,
'approvalsRequired' => $approvalsRequired,
'disableTransactionNotifications' => $disableTransactionNotifications,
'buildDefaults' => $buildDefaults,
'coinSpecific' => $coinSpecific,
], $extra);
return $wallet;
}

/**
* Freeze the wallet: block every send from it until the freeze expires. A freeze can't be lifted early.
*
* @param int $duration How long to freeze the wallet, in seconds
* @param string|null $reason Why, for example 'UserRequest' or 'TxIntentMismatch'
* @param string|null $referenceId Your own ID for the freeze, for tracking
* @param array<string, mixed> $extra More body params, for ones this method doesn't name yet
* @return array{time: string, expires: string, reason?: string, referenceId?: string, adminOrUserId?: string, ...}
* @throws BitGoException
*/
public function freeze(int $duration = 3600, ?string $reason = null, ?string $referenceId = null, array $extra = []): array
{
/** @var array{time: string, expires: string, reason?: string, referenceId?: string, adminOrUserId?: string, ...} $freeze BitGo's documented shape, not checked at runtime */
$freeze = $this->http->post('{coin}/wallet/{walletId}/freeze', $this->path(), [
'duration' => $duration,
'reason' => $reason,
'referenceId' => $referenceId,
], $extra);
return $freeze;
}

/**
* The most the wallet can send in one transaction, after fees.
*
* The filters are for UTXO coins: they pick which unspents count. Values are in base units.
*
* @param int|null $limit Use at most this many unspents, up to 500
* @param Amount|string|int|null $minValue Ignore unspents smaller than this
* @param Amount|string|int|null $maxValue Ignore unspents larger than this
* @param int|null $minHeight Ignore unspents below this block height
* @param int|null $minConfirms Ignore unspents from other wallets with fewer confirmations than this
* @param bool|null $enforceMinConfirmsForChange Apply $minConfirms to change unspents too
* @param int|null $feeRate The fee rate to use, in base units per kB
* @param int|null $maxFeeRate The highest fee rate to use when BitGo estimates it
* @param int|null $numBlocks BTC: estimate a fee rate that confirms within this many blocks
* @param list<string>|null $unspentIds Use only these unspents
* @param array<string, mixed> $extra More query params, for ones this method doesn't name yet
* @return array{coin: string, maximumSpendable: string, ...}
* @throws BitGoException
*/
public function maximumSpendable(
?int $limit = null,
Amount|string|int|null $minValue = null,
Amount|string|int|null $maxValue = null,
?int $minHeight = null,
?int $minConfirms = null,
?bool $enforceMinConfirmsForChange = null,
?int $feeRate = null,
?int $maxFeeRate = null,
?int $numBlocks = null,
?array $unspentIds = null,
array $extra = [],
): array {
/** @var array{coin: string, maximumSpendable: string, ...} $spendable BitGo's documented shape, not checked at runtime */
$spendable = $this->http->get('{coin}/wallet/{walletId}/maximumSpendable', $this->path(), [
'limit' => $limit,
'minValue' => $minValue,
'maxValue' => $maxValue,
'minHeight' => $minHeight,
'minConfirms' => $minConfirms,
'enforceMinConfirmsForChange' => $enforceMinConfirmsForChange,
'feeRate' => $feeRate,
'maxFeeRate' => $maxFeeRate,
'numBlocks' => $numBlocks,
'unspentIds' => $unspentIds,
], $extra);
return $spendable;
}

/**
* The wallet's receive addresses. Sends no request.
*/
Expand Down
123 changes: 123 additions & 0 deletions src/Wallets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php

/**
* ____ _ _ ____ ____ ____ _ __
* | __ )(_) |_ / ___| ___/ ___|| _ \| |/ /
* | _ \| | __| | _ / _ \___ \| | | | ' /
* | |_) | | |_| |_| | (_) |__) | |_| | . \
* |____/|_|\__|\____|\___/____/|____/|_|\_\
*
* @package BitGoSDK PHP
* @author Neto Melo <neto737@live.com>
* @license https://opensource.org/licenses/MIT MIT License
*/

declare(strict_types=1);

namespace neto737\BitGoSDK;

use neto737\BitGoSDK\Exception\BitGoException;
use neto737\BitGoSDK\Internal\Http;

/**
* Your wallets of every coin: /api/v2/wallets and /api/v2/wallet/balances.
*
* For one coin's wallets, use Coin::wallets(). To work with one wallet, take its coin and ID from here and use
* BitGo::coin($coin)->wallet($id).
*/
final readonly class Wallets
{
/**
* @internal Use BitGo::wallets().
*/
public function __construct(private Http $http)
{
}

/**
* List your wallets of every coin. Sends nothing until you iterate, then one request per batch.
*
* Each item has the same shape as Wallet::get() returns, and its 'coin' says which coin it is.
*
* @param int|null $limit How many wallets each request fetches. This is a batch size, not a total.
* @param list<CoinCode|string>|null $coin Only wallets of these coins
* @param list<string>|null $enterprise Only wallets in these enterprises, by ID
* @param list<string>|null $type Only wallets of these types, for example 'hot', 'cold' or 'custodial'
* @param string|null $labelContains Only wallets whose label contains this text
* @param bool|null $deleted true for only deleted wallets, false for only wallets that aren't
* @param bool|null $expandBalance Include each wallet's balances
* @param bool|null $excludeSpendableBalance With $expandBalance, return only confirmed balances, which is faster
* @param array<string, mixed> $extra More query params, for ones this method doesn't name yet
*/
public function list(
?int $limit = null,
?array $coin = null,
?array $enterprise = null,
?array $type = null,
?string $labelContains = null,
?bool $deleted = null,
?bool $expandBalance = null,
?bool $excludeSpendableBalance = null,
array $extra = [],
): Paginator {
return new Paginator($this->http, 'wallets', [], [
'limit' => $limit,
'coin' => self::codes($coin),
'enterprise' => $enterprise,
'type' => $type,
'labelContains' => $labelContains,
'deleted' => $deleted,
'expandBalance' => $expandBalance,
'excludeSpendableBalance' => $excludeSpendableBalance,
], $extra, 'wallets');
}

/**
* The total balances of your wallets, added up per coin. Amounts are strings in base units.
*
* @param list<CoinCode|string>|null $coin Only these coins
* @param list<string>|null $enterprise Only wallets in these enterprises, by ID
* @param list<string>|null $type Only wallets of these types, for example 'hot', 'cold' or 'custodial'
* @param string|null $labelContains Only wallets whose label contains this text
* @param bool|null $allTokens Include the totals of tokens, such as ERC20 and Stellar tokens
* @param bool|null $excludeEmptyBalances Leave out tokens with a zero balance
* @param bool|null $excludeSpendableBalances Return only confirmed balances, which is faster
* @param bool|null $includeStakingBalances Also return the staked and reward totals
* @param array<string, mixed> $extra More query params, for ones this method doesn't name yet
* @return array{balances: list<array{coin: string, balanceString: string, confirmedBalanceString: string, spendableBalanceString?: string, stakingBalanceString?: string, rewardBalanceString?: string, ...}>, ...}
* @throws BitGoException
*/
public function balances(
?array $coin = null,
?array $enterprise = null,
?array $type = null,
?string $labelContains = null,
?bool $allTokens = null,
?bool $excludeEmptyBalances = null,
?bool $excludeSpendableBalances = null,
?bool $includeStakingBalances = null,
array $extra = [],
): array {
/** @var array{balances: list<array{coin: string, balanceString: string, confirmedBalanceString: string, spendableBalanceString?: string, stakingBalanceString?: string, rewardBalanceString?: string, ...}>, ...} $balances BitGo's documented shape, not checked at runtime */
$balances = $this->http->get('wallet/balances', [], [
'coin' => self::codes($coin),
'enterprise' => $enterprise,
'type' => $type,
'labelContains' => $labelContains,
'allTokens' => $allTokens,
'excludeEmptyBalances' => $excludeEmptyBalances,
'excludeSpendableBalances' => $excludeSpendableBalances,
'includeStakingBalances' => $includeStakingBalances,
], $extra);
return $balances;
}

/**
* @param list<CoinCode|string>|null $coins
* @return list<string>|null
*/
private static function codes(?array $coins): ?array
{
return $coins === null ? null : array_map(static fn (CoinCode|string $coin): string => $coin instanceof CoinCode ? $coin->value : $coin, $coins);
}
}
Loading
Loading