Alluo Explained
Search
⌃K

Interacting with the Exchange

Import the interface, exchange. That's it!
IExchange.sol
1
// SPDX-License-Identifier: MIT
2
pragma solidity ^0.8.11;
3
​
4
interface IExchange{
5
function exchange(
6
address from,
7
address to,
8
uint256 amountIn,
9
uint256 minAmountOut
10
) external payable returns (uint256);
11
}
Import the interface above, then assuming that you have given ERC20 approval to the exchange,
​
If you'd like to send ERC20 and receive ERC20:
ERC20 -> ERC20
1
address exchangeAddress = 0x29c66CF57a03d41Cfe6d9ecB6883aa0E2AbA21Ec;
2
uint256 wethAmount = IExchange(exchangeAddress).exchange(usdcAddress, wethAddress, 10*10**6, 0);
3
// This exchanges 10 usdc to weth
If you'd like to send native ETH and receive ERC20:
Native ETH -> ERC20
1
address exchangeAddress = 0x29c66CF57a03d41Cfe6d9ecB6883aa0E2AbA21Ec;co
2
address nativeETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
3
uint256 usdcAmount= IExchange(exchangeAddress).exchange{value: 10**18}(nativeETH , usdcAddress, 10**18, 0);
4
// This exchanges 1 native ETH to usdc
If you'd like to send ERC20 and receive native ETH:
ERC20 -> Native ETH
1
address exchangeAddress = 0x29c66CF57a03d41Cfe6d9ecB6883aa0E2AbA21Ec;co
2
address nativeETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
3
receive() external payable {}
4
uint256 nativeWETH= IExchange(exchangeAddress).exchange(usdcAddress, nativeETH, 10*10**6, 0);
5
// This exchanges 10 usdc to native WETHI
If you find that it is reverting, please check the two causes below: 1. Not enough ERC20 approval to transfer tokens
2. No route preconfigured in the exchange