Skip to content

Commit bb78914

Browse files
theekrystalleegitbook-bot
authored andcommitted
Docs: add Whbar documentation #28
1 parent 93c9e4b commit bb78914

24 files changed

+148
-26
lines changed
395 KB
Loading

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Learn to use Hedera network services and build your first dApp with step-by-step
4343

4444
Learn about the suite of network services offered on Hedera and how each can be used to build decentralized applications.
4545

46-
<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td><a href="sdks-and-apis/hedera-api/readme-1-1/"><strong>Smart Contracts</strong></a></td><td>An EVM-based smart contract service. Build and deploy contracts using Solidity or port over an existing smart contract with ease.</td><td><a href="sdks-and-apis/hedera-api/readme-1-1/">readme-1-1</a></td><td><a href=".gitbook/assets/smart-contracts-icon.png">smart-contracts-icon.png</a></td></tr><tr><td><a href="sdks-and-apis/hedera-api/token-service/"><strong>Token Service</strong></a></td><td>Configure, mint, and manage native fungible and non-fungible tokens or using ERC-20 &#x26; 721 standards on the Hedera network.</td><td><a href="sdks-and-apis/hedera-api/token-service/">token-service</a></td><td><a href=".gitbook/assets/token-service-icon.png">token-service-icon.png</a></td></tr><tr><td><a href="sdks-and-apis/sdks/consensus-service/"><strong>Consensus Service</strong></a></td><td>Incorporate scalable, real-time, auditable logs of events with consensus timestamps into any web2 or permissionless web3 application.</td><td><a href="sdks-and-apis/sdks/consensus-service/">consensus-service</a></td><td><a href=".gitbook/assets/consensus-service-icon.png">consensus-service-icon.png</a></td></tr><tr><td><a href="sdks-and-apis/deprecated/sdks/readme-1-1/"><strong>File Service</strong></a></td><td>Hedera File Service is a decentralized file storage platform that allows users to securely store and access files on a distributed network of computers using hash as a file identifier.</td><td><a href="sdks-and-apis/deprecated/sdks/readme-1-1/">readme-1-1</a></td><td><a href=".gitbook/assets/file-service-icon.png">file-service-icon.png</a></td></tr></tbody></table>
46+
<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td><a href="sdks-and-apis/hedera-api/smart-contracts/"><strong>Smart Contracts</strong></a></td><td>An EVM-based smart contract service. Build and deploy contracts using Solidity or port over an existing smart contract with ease.</td><td><a href="sdks-and-apis/hedera-api/smart-contracts/">smart-contracts</a></td><td><a href=".gitbook/assets/smart-contracts-icon.png">smart-contracts-icon.png</a></td></tr><tr><td><a href="sdks-and-apis/hedera-api/token-service/"><strong>Token Service</strong></a></td><td>Configure, mint, and manage native fungible and non-fungible tokens or using ERC-20 &#x26; 721 standards on the Hedera network.</td><td><a href="sdks-and-apis/hedera-api/token-service/">token-service</a></td><td><a href=".gitbook/assets/token-service-icon.png">token-service-icon.png</a></td></tr><tr><td><a href="sdks-and-apis/sdks/consensus-service/"><strong>Consensus Service</strong></a></td><td>Incorporate scalable, real-time, auditable logs of events with consensus timestamps into any web2 or permissionless web3 application.</td><td><a href="sdks-and-apis/sdks/consensus-service/">consensus-service</a></td><td><a href=".gitbook/assets/consensus-service-icon.png">consensus-service-icon.png</a></td></tr><tr><td><a href="sdks-and-apis/deprecated/sdks/readme-1-1/"><strong>File Service</strong></a></td><td>Hedera File Service is a decentralized file storage platform that allows users to securely store and access files on a distributed network of computers using hash as a file identifier.</td><td><a href="sdks-and-apis/deprecated/sdks/readme-1-1/">readme-1-1</a></td><td><a href=".gitbook/assets/file-service-icon.png">file-service-icon.png</a></td></tr></tbody></table>
4747

4848
## EVM-Compatible Tools
4949

SUMMARY.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
* [ERC-3643 Real World Assets (RWA)](core-concepts/smart-contracts/tokens-managed-by-smart-contracts/erc-3643-real-world-assets-rwa.md)
130130
* [ERC-1363 (Payable Tokens)](core-concepts/smart-contracts/tokens-managed-by-smart-contracts/erc-1363-payable-tokens.md)
131131
* [Hedera Token Service System Contract](core-concepts/smart-contracts/tokens-managed-by-smart-contracts/hedera-token-service-system-contract.md)
132+
* [Wrapped HBAR (WHBAR)](core-concepts/smart-contracts/wrapped-hbar-whbar.md)
132133
* [Smart Contract Rent](core-concepts/smart-contracts/smart-contract-rent.md)
133134
* [Smart Contract Security](core-concepts/smart-contracts/security.md)
134135
* [EVM Archive Node Queries](core-concepts/smart-contracts/evm-archive-node-queries.md)
@@ -419,24 +420,24 @@
419420
* [TokenGetNftInfo](sdks-and-apis/hedera-api/token-service/tokengetnftinfo.md)
420421
* [TokenGetNftInfos](sdks-and-apis/hedera-api/token-service/tokengetnftinfos.md)
421422
* [TokenGetAccountNftInfo](sdks-and-apis/hedera-api/token-service/tokengetaccountnftinfo.md)
422-
* [File Service](sdks-and-apis/hedera-api/readme-1/README.md)
423-
* [FileService](sdks-and-apis/hedera-api/readme-1/fileservice.md)
424-
* [FileCreate](sdks-and-apis/hedera-api/readme-1/filecreate.md)
425-
* [FileAppend](sdks-and-apis/hedera-api/readme-1/fileappend.md)
426-
* [FileUpdate](sdks-and-apis/hedera-api/readme-1/fileupdate.md)
427-
* [FileDelete](sdks-and-apis/hedera-api/readme-1/filedelete.md)
428-
* [FileGetContents](sdks-and-apis/hedera-api/readme-1/filegetcontents.md)
429-
* [FileGetInfo](sdks-and-apis/hedera-api/readme-1/filegetinfo.md)
430-
* [Smart Contracts](sdks-and-apis/hedera-api/readme-1-1/README.md)
431-
* [SmartContractService](sdks-and-apis/hedera-api/readme-1-1/smartcontractservice.md)
432-
* [ContractCall](sdks-and-apis/hedera-api/readme-1-1/contractcall.md)
433-
* [ContractCallLocal](sdks-and-apis/hedera-api/readme-1-1/contractcalllocal.md)
434-
* [ContractCreate](sdks-and-apis/hedera-api/readme-1-1/contractcreate.md)
435-
* [ContractUpdate](sdks-and-apis/hedera-api/readme-1-1/contractupdate.md)
436-
* [ContractDelete](sdks-and-apis/hedera-api/readme-1-1/contractdelete.md)
437-
* [ContractGetByteCode](sdks-and-apis/hedera-api/readme-1-1/contractgetbytecode.md)
438-
* [ContractGetInfo](sdks-and-apis/hedera-api/readme-1-1/contractgetinfo.md)
439-
* [ContractGetRecords](sdks-and-apis/hedera-api/readme-1-1/contractgetrecords.md)
423+
* [File Service](sdks-and-apis/hedera-api/file-service/README.md)
424+
* [FileService](sdks-and-apis/hedera-api/file-service/fileservice.md)
425+
* [FileCreate](sdks-and-apis/hedera-api/file-service/filecreate.md)
426+
* [FileAppend](sdks-and-apis/hedera-api/file-service/fileappend.md)
427+
* [FileUpdate](sdks-and-apis/hedera-api/file-service/fileupdate.md)
428+
* [FileDelete](sdks-and-apis/hedera-api/file-service/filedelete.md)
429+
* [FileGetContents](sdks-and-apis/hedera-api/file-service/filegetcontents.md)
430+
* [FileGetInfo](sdks-and-apis/hedera-api/file-service/filegetinfo.md)
431+
* [Smart Contracts](sdks-and-apis/hedera-api/smart-contracts/README.md)
432+
* [SmartContractService](sdks-and-apis/hedera-api/smart-contracts/smartcontractservice.md)
433+
* [ContractCall](sdks-and-apis/hedera-api/smart-contracts/contractcall.md)
434+
* [ContractCallLocal](sdks-and-apis/hedera-api/smart-contracts/contractcalllocal.md)
435+
* [ContractCreate](sdks-and-apis/hedera-api/smart-contracts/contractcreate.md)
436+
* [ContractUpdate](sdks-and-apis/hedera-api/smart-contracts/contractupdate.md)
437+
* [ContractDelete](sdks-and-apis/hedera-api/smart-contracts/contractdelete.md)
438+
* [ContractGetByteCode](sdks-and-apis/hedera-api/smart-contracts/contractgetbytecode.md)
439+
* [ContractGetInfo](sdks-and-apis/hedera-api/smart-contracts/contractgetinfo.md)
440+
* [ContractGetRecords](sdks-and-apis/hedera-api/smart-contracts/contractgetrecords.md)
440441
* [Miscellaneous](sdks-and-apis/hedera-api/miscellaneous/README.md)
441442
* [Duration](sdks-and-apis/hedera-api/miscellaneous/duration.md)
442443
* [ExchangeRate](sdks-and-apis/hedera-api/miscellaneous/exchangerate.md)
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Wrapped HBAR (WHBAR)
2+
3+
## WHBAR (ERC) in the Hedera Ecosystem
4+
5+
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.
6+
7+
***
8+
9+
## Core Functionalities
10+
11+
* **Deposit & Mint:**
12+
13+
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.
14+
* **Withdraw & Burn:**
15+
16+
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.
17+
* **ERC20 Standard Compliance:**
18+
19+
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.
20+
21+
<figure><img src="../../.gitbook/assets/unwrapping-hbar-mermaid.png" alt=""><figcaption><p>HBAR wrapping/unwrapping flow from user wallet</p></figcaption></figure>
22+
23+
***
24+
25+
## Implementation Guide
26+
27+
Developers can integrate WHBAR into their applications by leveraging the following functions.&#x20;
28+
29+
### Wrapping HBAR
30+
31+
To convert HBAR into its ERC20 representation (WHBAR), use the `deposit()` function. Keep in mind that:
32+
33+
* **Native HBAR:** Uses **8** decimal places (**tinybars**).
34+
* **WHBAR (ERC20):** Uses **8** decimal places (**tinybars**)and _ONLY for deposits_ (wrapping) uses 18 decimal places (weibars).
35+
36+
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):
37+
38+
{% code overflow="wrap" %}
39+
```solidity
40+
/**
41+
* @notice Deposits HBAR and mints an equivalent amount of WHBAR
42+
* @dev This is the only supported method for obtaining WHBAR
43+
*/
44+
function deposit() public payable {
45+
// To wrap 10 HBAR into WHBAR
46+
// Note: 1 HBAR = 10^18 weibars; conversion handles the decimal difference.
47+
whbarContract.deposit{value: 10 * 10**18}();
48+
}
49+
```
50+
{% endcode %}
51+
52+
### Unwrapping WHBAR
53+
54+
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:
55+
56+
{% code overflow="wrap" %}
57+
```solidity
58+
/**
59+
* @notice Burns WHBAR tokens and returns the equivalent HBAR
60+
* @param amount The amount of WHBAR to burn
61+
*/
62+
function withdraw(uint256 amount) public {
63+
// To unwrap 5 WHBAR back to HBAR
64+
whbarContract.withdraw(5 * 10**8);
65+
}
66+
```
67+
{% endcode %}
68+
69+
This burns 5 WHBAR and sends back 5 HBAR to the wallet.
70+
71+
{% hint style="success" %}
72+
#### **Important Note: Decimal Nuance**
73+
74+
When depositing HBAR, remember the conversion nuances between decimal places.
75+
76+
* **Native HBAR & WHBAR Token:** 8 decimals (tinybars).&#x20;
77+
* **RPC `msg.value`:** 18 decimals (weibars).&#x20;
78+
79+
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.
80+
{% endhint %}
81+
82+
***
83+
84+
## Standard ERC20 Functions
85+
86+
WHBAR supports all standard ERC20 operations:
87+
88+
<table><thead><tr><th width="145.08203125">Function</th><th width="205.3828125">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>
89+
90+
***
91+
92+
## Contract Deployments
93+
94+
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).
95+
96+
<table><thead><tr><th width="173.6015625">Network</th><th width="146.49609375">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&#x26;pr=1&#x26;ps=1&#x26;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>
97+
98+
_**Source Code:**_ [_WHBAR.sol_](https://github.com/hashgraph/hedera-smart-contracts/blob/main/contracts/wrapped-tokens/WHBAR.sol)
99+
100+
***
101+
102+
## **Security Considerations:&#x20;**_**Audit and Testing**_
103+
104+
* **Audit and Review:**\
105+
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.
106+
* **Test in a Sandbox:**\
107+
Always test interactions in a testnet environment before deploying or integrating with mainnet contracts. This helps ensure the behavior matches expectations.
108+
* **Follow Best Practices:**\
109+
Double-check function inputs and transaction amounts. Always use the designated functions (`deposit()` and `withdraw()`) to prevent unintended fund loss.
110+
111+
***
112+
113+
## Integration Best Practices
114+
115+
* **Check allowances**: Before attempting `transferFrom` operations, verify that sufficient allowance has been granted.
116+
* **Verify contract addresses**: Always double-check you're interacting with the official WHBAR contract addresses listed in the documentation.
117+
* **Handle decimals properly**: Since both HBAR and WHBAR use 8 decimals, calculations are straightforward. Only for deposits, use 18 decimals to represent weibars.
118+
119+
{% hint style="danger" %}
120+
**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.
121+
{% endhint %}

0 commit comments

Comments
 (0)