I have the following contract. When I try to call swap_token function from the RemixIDE, I get the error:
Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? execution reverted
I specify the amount of ETH as an argument of the function.
I also tried to call the function using python web3 library using the following code:
contract_address = ''
signature = ''
from_address = ''
goerli_url = 'https://goerli.infura.io/v3/'
w3 = Web3(Web3.HTTPProvider(goerli_url))
contract = w3.eth.contract(address = contract_address,abi = abi)
nonce = w3.eth.get_transaction_count(from_address)
tprint('Uniswap project')
print(contract.functions.get_balance().call())
key = contract.functions.swap_token(10000000000000000).buildTransaction({'from':from_address,'nonce':nonce})
tx_code = w3.eth.signTransaction(key,signature)
w3.eth.sendRawTransaction(tx_code.rawTransaction)
But I'm getting the error:
raise ContractLogicError('execution reverted')
web3.exceptions.ContractLogicError: execution reverted
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract Uniswap {
address private constant uniswap_goerli = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f';
address private constant WETH_Goerli = '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6';
address private constant ETH_Goerli = '0x7af963cF6D228E564e2A0aA0DdBF06210B38615D';
function swap_token(uint _amount_to_send) public {
// uint amount_to_send = _amount_to_send * 1e18;
IERC20(ETH_Goerli).transferFrom(msg.sender, address(this),_amount_to_send);
IERC20(ETH_Goerli).approve(uniswap_goerli,_amount_to_send);
}
function get_balance() public view returns(uint) {
return address(this).balance;
}
Could you help and tell me how I should call via Remix and Web3 library?
ETH_Goerli
token?