I have a smart contract:
pragma solidity 0.5.3;
import "./ERC20.sol";
contract Transfer {
ERC20 private erc20iface;
address private _owner;
modifier validOwner() {
require(msg.sender == _owner);
_;
}
constructor() public {
_owner = msg.sender;
}
function () external payable {}
function transferTo(address[] memory receivers, uint[] memory amounts, address token) {
//Some code uses ERC20 methods/or simple transfers with .call()
}
}
When I try to deploy the contract in Remix
it shows the transaction cost
= 424652
gas.
However when I try to estimate gas limit with web3 .estimateGas()
const contractData = {
data: '0x123',
arguments: []
};
const contract = new web3.eth.Contract(CONTRACT_ABI).deploy(
contractData
);
const gasLimit = await contract.estimateGas();
I get gasLimit = 409652
And when I try to deploy, I receive an error: Out of gas
But if I use the amount of gas from Remix (424652
) it works fine.
What can be the reason of such differences (15000 gas, like if .estimateGas is missing ERC20 import)? And how to estimate the gasLimit
with .estimateGas()
correctly?