> ## Documentation Index
> Fetch the complete documentation index at: https://hedera-0c6e0218-docs-g53-fix-msgvalue-decimals-clarity.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Wrapped HBAR (WHBAR)

## WHBAR (ERC) in the Hedera Ecosystem

Wrapped HBAR (WHAR) is an ERC-compatible wrapper that follows the ERC20 standard for Hedera's native HBAR token. Built on widely adopted wrapper contract principles, WHBAR makes it easier for developers and users to integrate Hedera’s native token into decentralized applications (dApps). This contract enables users to seamlessly convert HBAR into an ERC20 token and vice versa, making it easier to integrate with the broader web3 and DeFi ecosystems.

***

## Core Functionalities

* **Deposit & Mint:**

  When you call the `deposit()` function and send HBAR, the contract mints an equivalent amount of WHBAR. Each unit of HBAR (represented in tinybars with 8 decimals) is matched with one unit of WHBAR. This ensures that the wrapped token maintains parity with the native token.
* **Withdraw & Burn:**

  To redeem your underlying HBAR, you call the `withdraw(amount)` function. The contract burns the specified WHBAR tokens and releases the corresponding HBAR back to your wallet. This burn mechanism is crucial for maintaining the correct token supply and preserving the peg between HBAR and WHBAR.
* **ERC20 Standard Compliance:**

  WHBAR implements all standard ERC20 functions (e.g., `transfer`, `approve`, `transferFrom`), ensuring seamless interaction with wallets, exchanges, and various DeFi protocols that support ERC20 tokens.

<Frame caption="HBAR wrapping/unwrapping flow from user wallet">
  <img src="https://mintcdn.com/hedera-0c6e0218-docs-g53-fix-msgvalue-decimals-clarity/8UNFtN4qYgBTXKkR/images/core-concepts/smart-contracts/wrapped-hbar-whbar/wrapped-hbar-whbar-1.png?fit=max&auto=format&n=8UNFtN4qYgBTXKkR&q=85&s=f9f61fae84d76cbb9ddd5880555940a8" width="2268" height="1804" data-path="images/core-concepts/smart-contracts/wrapped-hbar-whbar/wrapped-hbar-whbar-1.png" />
</Frame>

***

## Implementation Guide

Developers can integrate WHBAR into their applications by leveraging the following functions.

### Wrapping HBAR

To convert HBAR into its ERC20 representation (WHBAR), use the `deposit()` function. Keep in mind that:

* **Native HBAR:** Uses **8** decimal places (**tinybars**).
* **WHBAR (ERC20):** Uses **8** decimal places (**tinybars**) throughout — balances, transfers, `deposit()`, and `withdraw()`. `deposit()` simply mints an amount of WHBAR equal to the `msg.value` it receives, and `msg.value` is tinybar during EVM execution. The 18-decimal weibar form is **only** the transaction `value` an *off-chain* caller submits; the relay converts it to tinybar before `deposit()` runs.

How you specify the value depends on **who calls `deposit()`**:

* **From off-chain tooling (ethers/viem/wallet):** set the transaction `value` in **weibar** (10¹⁸ per HBAR). The relay converts it to tinybar, so sending `10 * 10**18` weibar wraps 10 HBAR → 10 WHBAR.
* **From another contract:** the `value` is **tinybar** (no conversion) — use `10 * 10**8` for 10 HBAR. Passing `10 * 10**18` here would send 10¹⁸ tinybar, which exceeds the total HBAR supply and reverts.

```solidity wrap theme={null}
/**
 * @notice Wrap 10 HBAR into WHBAR from within a contract.
 * @dev Contract-to-contract `value` is TINYBAR (8 decimals): 1 HBAR = 1e8.
 */
function wrapTenHbar() public {
    whbarContract.deposit{value: 10 * 10**8}(); // 10 HBAR
}
```

### Unwrapping WHBAR

When you want to convert back to redeem WHBAR for native HBAR, call the `withdraw()` function with `amount` in **tinybars** (10⁸ per HBAR). The value in WHBAR is directly mapped back to HBAR with the same 8 decimal places:

```solidity wrap theme={null}
/**
 * @notice Burns WHBAR tokens and returns the equivalent HBAR
 * @param amount The amount of WHBAR to burn
 */
function withdraw(uint256 amount) public {
    // To unwrap 5 WHBAR back to HBAR
    whbarContract.withdraw(5 * 10**8);
}
```

This burns 5 WHBAR and sends back 5 HBAR to the wallet.

<Check>
  #### **Important Note: Decimal Nuance**

  When depositing HBAR, remember the conversion nuances between decimal places.

  * **Native HBAR & WHBAR token:** 8 decimals (tinybars) — including `msg.value` inside `deposit()`.
  * **Transaction `value` from an off-chain caller:** 18 decimals (weibars), which the relay converts to tinybar before execution.

  `deposit()` mints WHBAR equal to `msg.value`, and `msg.value` is **tinybar** during execution — WHBAR is 8-decimal throughout. The 18-decimal weibar form applies only to the `value` an *off-chain* caller puts in the transaction; a **contract** calling `deposit{value: X}` must pass tinybar (1 HBAR = `1e8`).
</Check>

***

## Standard ERC20 Functions

WHBAR supports all standard ERC20 operations:

<table><thead><tr><th>Function</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td><code>transfer</code></td><td>Send WHBAR directly to another address</td><td><code>whbar.transfer(recipient, amount)</code></td></tr><tr><td><code>approve</code></td><td>Authorize a third party to spend your WHBAR</td><td><code>whbar.approve(spender, amount)</code></td></tr><tr><td><code>transferFrom</code></td><td>Transfer WHBAR as an authorized spender</td><td><code>whbar.transferFrom(owner, recipient, amount)</code></td></tr><tr><td><code>balanceOf</code></td><td>Check WHBAR balance of an address</td><td><code>whbar.balanceOf(address)</code></td></tr><tr><td><code>totalSupply</code></td><td>Get the total amount of WHBAR in circulation</td><td><code>whbar.totalSupply()</code></td></tr></tbody></table>

***

## Contract Deployments

The WHBAR contract implementation is available on GitHub in the [Hedera Smart Contracts repository](https://github.com/hashgraph/hedera-smart-contracts/blob/main/contracts/wrapped-tokens/WHBAR.sol).

<table><thead><tr><th>Network</th><th>Contract ID</th><th>EVM Address</th></tr></thead><tbody><tr><td><strong>✅ Hedera Mainnet</strong></td><td><a href="https://hashscan.io/mainnet/contract/0.0.8840785">0.0.8840785</a></td><td>0xb1F616b8134F602c3Bb465fB5b5e6565cCAd37Ed</td></tr><tr><td><strong>✅ Hedera Testnet</strong></td><td><a href="https://hashscan.io/testnet/contract/0.0.5816542?pa=1&pr=1&ps=1&pf=1">0.0.5816542</a></td><td>0xb1F616b8134F602c3Bb465fB5b5e6565cCAd37Ed</td></tr><tr><td>🔜 <strong>Other Networks</strong></td><td>Coming soon</td><td>Coming soon</td></tr></tbody></table>

***Source Code:*** [*WHBAR.sol*](https://github.com/hashgraph/hedera-smart-contracts/blob/main/contracts/wrapped-tokens/WHBAR.sol)

***

## Security Considerations:Audit and Testing

* **Audit and Review:**\
  Although the [WHBAR contract has been independently reviewed](https://hedera.com/audits-and-standards), developers and users should conduct their own security assessments. Even small oversights in smart contracts may lead to vulnerabilities.
* **Test in a Sandbox:**\
  Always test interactions in a testnet environment before deploying or integrating with mainnet contracts. This helps ensure the behavior matches expectations.
* **Follow Best Practices:**\
  Double-check function inputs and transaction amounts. Always use the designated functions (`deposit()` and `withdraw()`) to prevent unintended fund loss.

***

## Integration Best Practices

* **Check allowances**: Before attempting `transferFrom` operations, verify that sufficient allowance has been granted.
* **Verify contract addresses**: Always double-check you're interacting with the official WHBAR contract addresses listed in the documentation.
* **Handle decimals properly**: Since both HBAR and WHBAR use 8 decimals, calculations are straightforward. Only for deposits, use 18 decimals to represent weibars.

<Danger>
  **Critical**: HBAR sent directly to the contract address through methods other than the **`deposit()`** function will be permanently locked in the contract due to Hedera’s CryptoTransfer mechanics.
</Danger>
