Contract ID: WhbarHelper
deposit
Code overview
Recommended gas limit: 100,000- JavaScript SDK
Next steps
Unwrap WHBAR for HBAR
Withdraw WHBAR back to native HBAR.
WHBAR overview
How WHBAR works and its security advisory.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Wrap native HBAR into WHBAR tokens at a 1:1 ratio through the WhbarHelper deposit function, with token association requirements and a code example.
WHBAR contract directly.WHBAR contract.WhbarHelper contract instead.TOKEN_NOT_ASSOCIATED_TO_ACCOUNT error.deposit
function deposit() public payable {
IWHBAR(whbarContract).deposit{value: msg.value}(msg.sender, msg.sender);
}
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);
Was this page helpful?