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

# Stake and unstake from code

> Exactly how staking, the 30-day exit and claiming behave on the sUSDh contract.

**Staking is one transaction. Leaving is two, with a 30-day wait in between.** This page describes how the contract behaves, so your app shows customers exactly what will happen.

## Stake

`stake(assets)` takes USDh from the caller and mints sUSDh to the same address at the current sUSDh price.

| | |
| - | - |
| Before | The customer approves the sUSDh contract to take their USDh |
| sUSDh received | USDh staked divided by the sUSDh price |
| Who receives it | Always the wallet that calls `stake`. There is no option to stake for another address |
| Fee | None. Only Ethereum's network fee |
| Minimum | None, as long as the amount buys at least one base unit of sUSDh |

## Unstake

**1. Ask to unstake**

`requestUnstake(shares)` burns the customer's sUSDh at once. The USDh they will receive is **fixed at the sUSDh price at that moment**. From then on, that amount no longer earns rewards.

**2. Wait 30 days**

The exit waits for the exit period. Read the exact time it ends from the contract rather than calculating it yourself: `pendingExit(customer)` returns the sUSDh waiting and `availableAt`, the time the exit can be claimed.

**3. Claim**

After `availableAt`, `claim()` sends the USDh to the customer. Nothing is sent automatically. Your app must show a claim button.

## Three behaviors to design around

> [accordion] Asking again restarts the wait
>
> A customer can have one pending exit at a time. If they ask to unstake more while waiting, both amounts are combined at an average price, and the full wait starts again for the total. Warn customers before they do this.

> [accordion] Claim and ask again in one step
>
> `claimAndRequestUnstake(shares)` claims a finished exit, if there is one, and starts a new one in the same transaction. Use it when a customer wants to leave in stages.

> [accordion] The price is fixed when they ask
>
> If the sUSDh price rises during the wait, the pending exit does not gain from it. Show the amount from `getUserView` (`exitingAssets6`), which is what the customer will receive.

## Example

```typescript unstake.ts theme={null}
// 1. Ask to unstake all the customer's sUSDh
const shares = await client.readContract({
  address: SUSDH, abi: susdhAbi, functionName: "balanceOf", args: [customer],
});
await walletClient.writeContract({
  address: SUSDH, abi: susdhAbi, functionName: "requestUnstake", args: [shares],
});

// 2. Later: show when it can be claimed
const [pendingShares, availableAt] = await client.readContract({
  address: SUSDH, abi: susdhAbi, functionName: "pendingExit", args: [customer],
});

// 3. After availableAt: claim
await walletClient.writeContract({
  address: SUSDH, abi: susdhAbi, functionName: "claim",
});
```

## When a call fails

| Error | Meaning |
| - | - |
| `zero assets` or `zero shares` | The amount is zero, or too small to buy one base unit of sUSDh |
| `nothing` | `claim` was called with no pending exit |
| `cooldown` | `claim` was called before `availableAt` |
| `from frozen` or `to frozen` | The customer's address is frozen on the USDh contract |
| `EnforcedPause()` | The USDh contract is paused, so USDh cannot move |

*Last updated: Nov 17, 2026*


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