Is it possible to call Uniswap from a smart contrat and make a swap with smart contract ether, and not from the message sender ether ? (and send back the swapped token to the owner)
I tried like this on Kovan testnet but it failed :
pragma solidity ^0.8.2;
import "https://github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/interfaces/IUniswapV2Router02.sol";
contract Coffre{
address owner =msg.sender;
IUniswapV2Router02 uni = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
address private token_address = 0x514910771AF9Ca656af840dff83E8264EcF986CA; //chainlink
function getPathForETHtoToken() private view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = uni.WETH();
path[1] = token_address;
return path;
}
function swapContractEthToLink() public {
uni.swapExactETHForTokens(0,getPathForETHtoToken(), owner, block.timestamp + 15);
}
Also with swapExactETHForTokens I can't specify how many Eth from the contract I want to swap so it's probably not the right function