In my smart contract, I would like to accept exactly 1 full HBAR unit in a payable function.
The following code would work in Ethereum, by specifying 1 ether.
pragma solidity 0.8.18;
contract Example {
function payMeOneHbar () public payable {
require(msg.value == 1 ether, "Payment required is exactly 1 HBAR");
/* ... other code */
}
}
Does Hedera have the equivalent concept to 1 ether?
(I cannot specify 1 hbar in Solidity, as that isn't recognised by solc.)
I tried accepting 1 HBAR and expected it would have the same function as 1 ether


Simply specify
100_000_000or10^8in place of1 ether, like so:Note that the absolute numerical value is different from that on Ethereum.
Detailed explanation
In Solidity syntax,
etheris simply a constant that is equal to10^18(1,000,000,000,000,000,000). Ref: Solidity Lang - Ether UnitsIn Solidity syntax there is no concept of
hbar, but we can use a constant value of10^8(100,000,000) in its place. Ref: Hedera - HBAR and Hedera Helpdesk - What are the official HBAR cryptocurrency denominations?Try it out
You can try this out manually using the following Solidity code:
Hot link to try this out in Remix
... and if you deploy it, and invoke each of the auto-generated getter functions, you should get this result:
As you can see, all of the
isOne...boolean values aretrue; and all theone...unsigned integer values are equal to the constants from the reference values copied above.