> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# getYieldPosition

# getYieldPosition

Gets a wallet's current balance in an [Earn](https://docs.dynamic.xyz/docs/earn/overview.md) vault. Reads on-chain, so the result always reflects the vault's current state, so there's no caching delay.

The response has two numbers, `shares` and `assets`. **Show `assets`, not `shares`, in your UI.**

* `assets` is what the wallet's position is worth right now, in the underlying token (e.g. USDC). This is the number that grows as yield accrues, and it's the balance and earnings your users care about.
* `shares` is an internal accounting number the vault uses to track ownership. For some providers it's set once at deposit time and doesn't change after that, even while the position is earning yield, so showing it to a user creates a second, unmoving "balance" that looks broken next to the real one.

> [!NOTE]
>
> For some providers, the position is a balance that grows as interest accrues, so `shares` and `assets` are always the same number. Showing `assets` is correct either way.

> [!NOTE]
>
> For a Solana vault, `shares` counts every share the wallet owns in the vault, including shares staked in the vault's farm. The position therefore does not change when a deposit's farm-staking transaction confirms.

> [!NOTE]
>
> Both `shares` and `assets` come back as raw strings (e.g. `"10500000"`), not human-readable numbers. Divide by the vault's `assetDecimals` (from [`getYieldDetails`](https://docs.dynamic.xyz/docs/javascript/reference/client/get-yield-details)) before displaying either one. See the example below.

## Usage

```javascript theme={"system"}
import { getYieldPosition } from '@dynamic-labs-sdk/client';

const position = await getYieldPosition({
  vaultId: 'fb-eth-galaxy-usdc-fw-01',
  walletAccount,
});

console.log(position.assets); // what to show a user — see "Show assets, not shares" below
```

## Parameters

| Parameter | Type | Description |
| - | - | - |
| `vaultId` | `string` | Opaque vault identifier, from [`listYieldVaults`](https://docs.dynamic.xyz/docs/javascript/reference/client/list-yield-vaults). |
| `walletAccount` | `WalletAccount` | The wallet account whose position in the vault is being read. Must be an EVM wallet account for an EVM vault, or a Solana wallet account for a Solana vault. |
| `client` | `DynamicClient` (optional) | The Dynamic client instance. Only required when using multiple Dynamic clients. |

## Returns

`Promise<YieldVaultPosition>` - The wallet's balance in the vault.

| Field | Type | Description |
| - | - | - |
| `vaultId` | `string` | Opaque vault identifier. |
| `ownerAddress` | `string` | The wallet address the position was read for. |
| `assets` | `string` | What the position is worth right now, in raw underlying-token units. Show this in your UI. |
| `shares` | `string` | Internal accounting balance, in raw share units. Not meaningful to show a user (see above). |

## Examples

### Format a position for display

```javascript theme={"system"}
import { getYieldDetails, getYieldPosition } from '@dynamic-labs-sdk/client';
import { formatUnits } from 'viem';

// Turns the raw `assets` string into a plain number like "10.5", ready to show a user.
async function loadBalance(vaultId, walletAccount) {
  const [details, position] = await Promise.all([
    getYieldDetails({ vaultId }),
    getYieldPosition({ vaultId, walletAccount }),
  ]);

  return {
    assetSymbol: details.assetSymbol,
    balance: formatUnits(BigInt(position.assets), details.assetDecimals),
  };
}
```

## React

`useGetYieldPosition` is a query hook that stays disabled until `walletAccount` is defined, so it's safe to render before a wallet is connected.

```tsx theme={"system"}
import { useGetYieldDetails, useGetYieldPosition } from '@dynamic-labs-sdk/react-hooks';
import type { WalletAccount } from '@dynamic-labs-sdk/client';
import { formatUnits } from 'viem';

function Balance({
  vaultId,
  walletAccount,
}: {
  vaultId: string;
  walletAccount: WalletAccount | undefined;
}) {
  const { data: details } = useGetYieldDetails({ vaultId });
  const { data: position, isLoading } = useGetYieldPosition({
    vaultId,
    walletAccount,
  });

  if (isLoading || !details) {
    return <p>Loading balance...</p>;
  }

  const balance = formatUnits(BigInt(position?.assets ?? '0'), details.assetDecimals);

  return <p>Balance: {balance} {details.assetSymbol}</p>;
}
```

## Related

* [`getYieldDetails`](https://docs.dynamic.xyz/docs/javascript/reference/client/get-yield-details) - Vault details, including `assetDecimals`
* [`getYieldPerformance`](https://docs.dynamic.xyz/docs/javascript/reference/client/get-yield-performance) - The wallet's earnings and return on capital in this vault
* [`getYieldEarnings`](https://docs.dynamic.xyz/docs/javascript/reference/client/get-yield-earnings) - The wallet's earnings across all vaults on a chain
* [`getYieldRewards`](https://docs.dynamic.xyz/docs/javascript/reference/client/get-yield-rewards) - The wallet's accrued rewards in this vault
* [`withdrawFromYieldVault`](https://docs.dynamic.xyz/docs/javascript/reference/client/withdraw-from-yield-vault) - Withdraw from this vault


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.