I am having a hard time creating a contract that uses the swapExactETHForTokens
function.
I intend to create a contract that receives ETH and then any user can swap those ETH for a specific token whose recipient is the same contract. Freezing those tokens (A token burning contract).
I'm using something like this, following the uniswap docs as a guide:
uint256 deadline = block.timestamp + 1800;
address[] path = [WETH, UBI]; //Each with its respective declared address
InterfaceUniswapV2Router(UNISWAP_V2_ROUTER_ADDRESS).swapExactETHForTokens
{value: address(this).balance}(1, path, address(this), deadline);
So far so good, I set a deadline of let's say 30 minutes, and I can make those swaps without any problem, however, when those 30 minutes of the first swap are reached, the contract does not allow me to make any other swap, sending me the error:
Fail with error 'UniswapV2Router: EXPIRED'.
It doesn't matter if I exceed the gas limit and the gas price. I always get that error.
This is one of the failed transactions of one of the instances https://kovan.etherscan.io/tx/0x446ab53eb290c9f5a40b34944c3dcb960843bef55a7a4fc00302270823c17bcc
Am I doing something wrong?