Swap HBAR for Tokens
Swap HBAR for HTS fungible tokens.
Last updated
Swap HBAR for HTS fungible tokens.
Last updated
Below are three methods available to swap HBAR for HTS tokens:
Swap an exact amount of HBAR for a minimum token amount.
Solidity function name: swapExactETHForTokens
uint amountOutMin
The minimum token amount to receive in its smallest unit
address[] calldata path
An ordered list of token EVM addresses
address to
EVM address for the token recipient
uint deadline
Deadline in Unix seconds
Set the minimum output token amount (amountOutMin) with caution.
A high minimum might lead to a swap failure due to insufficient liquidity or rapid price movements. Conversely, setting the minimum too low can expose you to significant slippage, potentially resulting in a financial loss as you might receive far fewer tokens than expected.
Resources:
Swap a maximum amount of HBAR to receive an exact tokens amount
Solidity function name: swapETHForExactTokens
uint amountOut
The exact output amount to receive in its smallest unit
address[] calldata path
An ordered list of token EVM addresses
address to
EVM address for the token recipient
uint deadline
Deadline in Unix seconds
Set the maximum HBAR amount (payable) with caution.
A low maximum might lead to a swap failure if the required liquidity surpasses this limit or due to rapid price movements. Conversely, setting it too high can expose you to significant slippage, potentially leading to a financial loss as you might spend far more HBAR than expected.
Resources:
Swap an exact amount of HBAR for a minimum token amount, supporting HTS tokens with custom fees on token transfer.
Solidity function name: swapExactETHForTokensSupportingFeeOnTransferTokens
uint amountOutMin
The minimum token amount to receive in its smallest unit
address[] calldata path
An ordered list of token EVM addresses
address to
EVM address for the token recipient
uint deadline
Deadline in Unix seconds
Set the minimum output token amount (amountOutMin) with caution.
A high minimum might lead to a swap failure due to insufficient liquidity or rapid price movements. Conversely, setting the minimum too low can expose you to significant slippage, potentially resulting in a financial loss as you might receive far fewer tokens than expected.
Resources: