Skip to content

Commit

Permalink
add docs for getPortfolioTokenBalances
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-defi committed Jan 17, 2025
1 parent 2f65eb9 commit 3d19876
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
51 changes: 51 additions & 0 deletions site/docs/pages/api/get-portfolio-token-balances.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# `getPortfolioTokenBalances`

The `getPortfolioTokenBalances` function returns an object containing an array of
portfolios for the provided addresses. Each portfolio is an object with the address
of the wallet, the fiat value of the portfolio, and an array of tokens held by the
provided address.

Before using this endpoint, make sure to obtain a [Client API Key](https://portal.cdp.coinbase.com/projects/api-keys/client-key)
from Coinbase Developer Platform.

## Usage

:::code-group

```tsx twoslash [code]
import { setOnchainKitConfig } from '@coinbase/onchainkit';
import { getPortfolioTokenBalances } from '@coinbase/onchainkit/api';

const response = await getPortfolioTokenBalances({
addresses: ['0x...'],
});
```

```json [return value]
"portfolios": [
{
"address": "0x...",
"portfolioBalanceInUsd": 100,
"tokenBalances": [{
"address": "0x...",
"chainId": 1,
"decimals": 18,
"image": "https://example.com/image.png",
"name": "Token Name",
"symbol": "TKN",
"cryptoBalance": 10,
"fiatBalance": 100
}]
}
]
```

:::

## Returns

[`Promise<GetPortfoliosAPIResponse>`](/api/types#getportfoliosapiresponse)

## Parameters

[`GetPortfolioTokenBalancesParams`](/api/types#getportfoliotokenbalancesparams)
20 changes: 19 additions & 1 deletion site/docs/pages/api/types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ type GetTokensResponse = Token[] | APIError;

## `GetTokenDetailsParams`

```ts
```ts
type GetTokenDetailsParams = {
contractAddress: Address;
tokenId?: string;
Expand Down Expand Up @@ -141,3 +141,21 @@ type BuildMintTransactionParams = {
```ts
type BuildMintTransactionResponse = MintTransaction | APIError;
```

## `GetPortfolioTokenBalancesParams`

```ts
type GetPortfolioTokenBalancesParams = {
addresses: Address[] | null | undefined;
};
```

## `PortfolioTokenBalances`

```ts
type PortfolioTokenBalances = {
address: Address;
portfolioBalanceInUsd: number;
tokenBalances: PortfolioTokenWithFiatValue[];
};
```

0 comments on commit 3d19876

Please sign in to comment.