Wrap HBAR for WHBAR

Deposit HBAR native cryptocurrency to retrieve Wrapped HBAR (WHBAR) tokens at a 1:1 ratio.

Contract ID: WhbarHelper

Ensure that the WHBAR token ID is associated with the account prior to calling the deposit function. Failure to do so will result in a TOKEN_NOT_ASSOCIATED_TO_ACCOUNT error


Function name: deposit

Solidity Function Body
//WhbarHelper.sol
function deposit() public payable {
  IWHBAR(whbarContract).deposit{value: msg.value}(msg.sender, msg.sender);
}

Code Overview

Recommended gas: 100,000 gwei (~ $0.009 USD)

Resources:

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);

Last updated