Can't transfer ETH from swap smart contract to user
I try to send back ether when user sell token in swap, and i have that error:
My solidity pragma: pragma solidity >=0.4.22 <0.9.0;
project:/contracts/ANQSwap.sol:33:9: ParserError: Expected primary expression.
payable(address(msg.sender)).transfer(etherToSendBack);
It's my function code:
function sellTokens(uint256 _value) public {
require(anteqToken.balanceOf(msg.sender) >= _value, "You doesn't have enought AnteqToken.");
uint256 etherToSendBack = _value/rate;
require(address(this).balance >= etherToSendBack, "AnteqToken Swap doesn't have enought Ether to buy yours token.");
anteqToken.transferFrom(msg.sender, address(this), _value);
payable(msg.sender).transfer(etherToSendBack);
}
And I too try
payable(address(msg.sender)).transfer(etherToSendBack);
Solution 1:
Fixed error
I added one pragma version to all .sol file
pragma solidity ^0.8.0
payable(msg.sender).transfer(etherToSendBack);
Code above works.
I leave this question for other dev if they encountern on similar problem.