diff --git a/site/docs/pages/api/get-portfolio-token-balances.mdx b/site/docs/pages/api/get-portfolio-token-balances.mdx new file mode 100644 index 0000000000..31bd2d4674 --- /dev/null +++ b/site/docs/pages/api/get-portfolio-token-balances.mdx @@ -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`](/api/types#getportfoliosapiresponse) + +## Parameters + +[`GetPortfolioTokenBalancesParams`](/api/types#getportfoliotokenbalancesparams) diff --git a/site/docs/pages/api/types.mdx b/site/docs/pages/api/types.mdx index e5eb515b4e..147c69e808 100644 --- a/site/docs/pages/api/types.mdx +++ b/site/docs/pages/api/types.mdx @@ -95,7 +95,7 @@ type GetTokensResponse = Token[] | APIError; ## `GetTokenDetailsParams` -```ts +```ts type GetTokenDetailsParams = { contractAddress: Address; tokenId?: string; @@ -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[]; +}; +```