> ## 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](/docs/overview/yield) vault. Reads on-chain, so the result always reflects the vault's current state — 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 — it's the balance and earnings your users care about.
* `shares` is an internal accounting number the vault uses to track ownership. It's set once at deposit time and doesn't change after that, even while the position is earning yield. Showing it to a user just creates a second, unmoving "balance" that looks broken next to the real one.

<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`](/docs/javascript/reference/client/get-yield-details) — before displaying either one. See the example below.
</Note>

## 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`](/docs/javascript/reference/client/list-yield-vaults). |
| `walletAccount` | `WalletAccount`            | The wallet account whose position in the vault is being read.                                      |
| `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 — 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`](/docs/javascript/reference/client/get-yield-details) - Vault details, including `assetDecimals`
* [`getYieldRewards`](/docs/javascript/reference/client/get-yield-rewards) - The wallet's accrued rewards in this vault
* [`withdrawFromYieldVault`](/docs/javascript/reference/client/withdraw-from-yield-vault) - Withdraw from this vault
