My smart contract holds a few WETH. I have this function in my contract:
function getFunds(address tokenAddress) external onlyOwner{
IERC20 token = IERC20(tokenAddress);
uint balance = token.balanceOf(address(this));
uint balanceOwner = token.balanceOf(owner);
assert(token.transfer(owner, balance));
assert(token.balanceOf(owner) == balanceOwner + balance);
}
I call getFunds with the correct WETH address and from the correct owner address.
But still, the tx reverts with 20% gas used, and I don't know why. What can be the reason?
I tested everything via hardhat and there it works.
EDIT: This is the way I call the contract in production via web3js:
let myContract = new web3.eth.Contract(myContractAbi, CONTRACT_ADDRESS)
const tx = myContract.methods.getFunds(WETH) //WETH constant with correct address
const data = tx.encodeABI()
let currentGasPriceInWei = parseInt(await web3.eth.getGasPrice())
const txData = {
from: OWNER_ADDRESS,
to: CONTRACT_ADDRESS,
data: data,
gasPrice: web3.utils.toBN(currentGasPriceInWei),
gas: 35000
}
web3.eth.sendTransaction(txData)
...
gas
parameter? Looking at fmtscan I can see wfmt transfers that take quite some more gas, so I would probably try setting this to 100k just to test it.