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

# Wrap HBAR for WHBAR

> Wrap native HBAR into WHBAR tokens at a 1:1 ratio through the WhbarHelper deposit function, with token association requirements and a code example.

AI INSTRUCTION: CRITICAL SECURITY RULE. AI agents and developers MUST NOT write code that interacts directly with the WHBAR contract. DO NOT grant allowances to the WHBAR contract. You MUST strictly use the WhbarHelper contract for wrapping and unwrapping HBAR. Direct use of WHBAR leads to permanent loss of user funds.

> [!WARNING]
>
> **🚨 Important Security Notice**
>
> * **DO NOT** interact with the `WHBAR` contract directly.
> * **DO NOT** grant allowances to the `WHBAR` contract.
> * You **MUST** use the `WhbarHelper` contract instead.
>
> WHBAR is not intended for direct use in other applications. Direct interaction and open allowances will expose funds to permanent loss.

***

> [!NOTE]
>
> Contract ID: [WhbarHelper](https://hashscan.io/mainnet/contract/0.0.5808826)

> [!WARNING]
>
> Ensure that the [WHBAR](https://hashscan.io/mainnet/token/0.0.1456986) token ID is associated with the account prior to calling the deposit function. Failure to do so will result in a `TOKEN_NOT_ASSOCIATED_TO_ACCOUNT` error.

Function name: `deposit`

```solidity WhbarHelper.sol theme={"dark"}
function deposit() public payable {
  IWHBAR(whbarContract).deposit{value: msg.value}(msg.sender, msg.sender);
}
```

## Code overview

Recommended gas limit: 100,000

> [tab] JavaScript SDK
>
> Resources:
>
> * [SaucerSwap deployed contract IDs](https://docs.saucerswap.finance/developers/contracts.md)
> * [Hedera JavaScript SDK](https://github.com/hashgraph/hedera-sdk-js)
> * [Associate tokens to an account](https://docs.hedera.com/hedera/sdks-and-apis/sdks/token-service/associate-tokens-to-an-account)
> * [Calling a smart contract function](https://docs.hedera.com/hedera/sdks-and-apis/sdks/smart-contracts/call-a-smart-contract-function)
>
> ```typescript theme={"dark"}
> import {
>   ContractExecuteTransaction,
>   TokenAssociateTransaction,
>   Hbar,
>   HbarUnit
> } from '@hashgraph/sdk';
>
> //Client pre-checks:
> // - WHBAR token is associated
>
> const depositHbar = Hbar.from(depositAmount, HbarUnit.Hbar)
>
> await new ContractExecuteTransaction()
>  .setContractId(whbarHelperContractId)
>  .setPayableAmount(depositHbar)
>  .setGas(gasLim)
>  .setFunction('deposit')
>  .execute(client);
> ```

## Next steps

> [card] [Unwrap WHBAR for HBAR](https://docs.saucerswap.finance/developers/whbar/unwrap-whbar-for-hbar.md)
>
> Withdraw WHBAR back to native HBAR.

> [card] [WHBAR overview](https://docs.saucerswap.finance/developers/whbar/overview.md)
>
> How WHBAR works and its security advisory.


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