> ## 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.

# Unwrap WHBAR for HBAR

> Unwrap WHBAR tokens back into native HBAR at a 1:1 ratio through the WhbarHelper unwrapWhbar function, including the required spender allowance setup.

<div style="display: none;">
  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.
</div>

<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.
</Warning>

***

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

<Warning>
  Granting a spender allowance to the **WhbarHelper** contract **is required** for the contract to transfer the [**WHBAR**](https://hashscan.io/mainnet/token/0.0.1456986) token from the user's wallet to the contract.
</Warning>

Function name: `unwrapWhbar`

| Parameter Name | Description                             |
| -------------- | --------------------------------------- |
| *uint256 wad*  | WHBAR token amount in its smallest unit |

<CodeGroup>
  ```solidity WhbarHelper.sol theme={"dark"}
  /// @notice Safely unwrap whbar to msg.sender
  /// @dev This contract needs an allowance from msg.sender to transfer the whbar token
  /// @param wad The amount to unwrap
  function unwrapWhbar(uint wad) public {
    require(wad > 0, "WhbarHelper: wad cannot be lt zero");
    // transfer the whbar to this contract
    HederaTokenHelper.safeTransferFrom(whbarToken, msg.sender, address(this), wad);

    // approve sending the whbar to the whbar contract
    HederaTokenHelper.safeApprove(whbarToken, whbarContract, wad);

    // use withdraw(address src, address dst, uint wad) and use this contract and msg.sender to withdraw
    // to the contract caller
    IWHBAR(whbarContract).withdraw(address(this), msg.sender, wad);
  }
  ```
</CodeGroup>

## Code overview

Recommended gas limit: 1,000,000

<Tabs>
  <Tab title="JavaScript SDK">
    Resources:

    * [SaucerSwap deployed contract IDs](/developers/contracts)
    * [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 {
      ContractFunctionParameters,
      ContractExecuteTransaction,
      TokenAssociateTransaction,
      Hbar,
      HbarUnit
    } from '@hashgraph/sdk';

    //Client pre-checks:
    // - WhbarHelper contract has spender allowance for WHBAR token

    const params = new ContractFunctionParameters();
    params.addUint256(withdrawAmount); //amount in token's smallest unit

    await new ContractExecuteTransaction()
      .setContractId(whbarHelperContractId)
      .setGas(gasLim)
      .setFunction('unwrapWhbar', params)
      .execute(client);
    ```
  </Tab>
</Tabs>

## Next steps

<CardGroup cols={2}>
  <Card title="Wrap HBAR for WHBAR" href="/developers/whbar/wrap-hbar-for-whbar">
    Deposit HBAR and receive WHBAR at 1:1.
  </Card>

  <Card title="WHBAR overview" href="/developers/whbar/overview">
    How WHBAR works and its security advisory.
  </Card>
</CardGroup>
