Wrapped HBAR (WHBAR)
Last updated
Was this helpful?
Last updated
Was this helpful?
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.
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.
Developers can integrate WHBAR into their applications by leveraging the following functions.
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)and ONLY for deposits (wrapping) uses 18 decimal places (weibars).
The conversion from HBAR to WHBAR involves adjusting for these decimal differences. For example, to wrap native HBAR into WHBAR, call deposit()
and send your HBAR as msg.value
in weibars (10¹⁸ per HBAR):
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:
This burns 5 WHBAR and sends back 5 HBAR to the wallet.
When depositing HBAR, remember the conversion nuances between decimal places.
Native HBAR & WHBAR Token: 8 decimals (tinybars).
RPC msg.value
: 18 decimals (weibars).
Although the deposit()
function requires input in 18 decimal weibars, WHBAR tokens and all related transfers and balances use 8 decimals, identical to native HBAR in tinybars.
WHBAR supports all standard ERC20 operations:
transfer
Send WHBAR directly to another address
whbar.transfer(recipient, amount)
approve
Authorize a third party to spend your WHBAR
whbar.approve(spender, amount)
transferFrom
Transfer WHBAR as an authorized spender
whbar.transferFrom(owner, recipient, amount)
balanceOf
Check WHBAR balance of an address
whbar.balanceOf(address)
totalSupply
Get the total amount of WHBAR in circulation
whbar.totalSupply()
✅ Hedera Mainnet
0xb1F616b8134F602c3Bb465fB5b5e6565cCAd37Ed
✅ Hedera Testnet
0xb1F616b8134F602c3Bb465fB5b5e6565cCAd37Ed
🔜 Other Networks
Coming soon
Coming soon
Audit and Review: Although the WHBAR contract has been independently reviewed, 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.
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.
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.
The WHBAR contract implementation is available on GitHub in the .
Source Code: