Contract ID: SaucerSwapV2SwapRouter
Consider the tokenโs decimal places when determining input and output values.Input and output amounts passed to the solidity function should all be in the tokenโs smallest unit. For the SAUCE token, which has 6 decimal places, an input of 123.45 SAUCE should be entered as 123450000 (123.45 multiplied by 10^6).
Granting an spender allowance to the router contract is required when the input token is not native HBAR for security reasons enforced at the native code layer. Ensure that the allowance amount is in tokenโs smallest unit.
Swap Exact Tokens for HBAR
Swap an exact amount of tokens for a minimum HBAR amount. Solidity function name: exactInputFor the ExactInputParams recipient, use the SwapRouter contract address. This is required for unwrapWHBAR to function correctly. The unwrapped HBAR will then be sent to the userโs recipient address.When the output token is not HBAR, use the userโs address as the recipient instead.
Code Overview
- JavaScript SDK
Resources:Note: The Hedera JavaScript SDK currently does not support passing complex contract function parameters. Instead, use Ethers.js or Web3.js to obtain the encoded function data and pass that data as a function parameter.
Typescript
Swap Tokens for Exact HBAR
Swap a maximum amount of tokens to receive an exact HBAR amount. Solidity function name: exactOutputFor the ExactInputParams recipient, use the SwapRouter contract address. This is required for unwrapWHBAR to function correctly. The unwrapped HBAR will then be sent to the userโs recipient address.When the output token is not HBAR, use the userโs address as the recipient instead.
Code Overview
- JavaScript SDK
Resources:Note: The Hedera JavaScript SDK currently does not support passing complex contract function parameters. Instead, use Ethers.js or Web3.js to obtain the encoded function data and pass that data as a function parameter.
Typescript