I have the following function to mint a nft on my smart contract (I am using the open zeppelin ERC721 contract) but I would like to stimate the gas feet from my web3 dapp. I know the formula is transaction cost * current gas price and I know I can find the current gas price using something like etherscan api or the ethgasstation.info api, and I know the minimum transaction cost is 21000 but I don't know how much is the costof my mint function in other to calculate a realistic gas fee for the minting, any help to calculate or to find my transaction cost?
here is my mint function:
function mint(uint256[] memory tokens) public payable {
require(saleIsActive, "Sale is not active");
if (
tokens.length == 0 || tokens > maxPurchase
) {
revert("number of tokens incorrect");
}
if (price * tokens.length >= msg.value) {
revert("Ether value is not correct");
}
if (_totalTokens.current() + tokens.length > MAX_TOKENS) {
revert("Purchase would exceed max supply");
}
for (uint256 i = 0; i < tokens.length; i++) {
_safeMint(msg.sender, gradisTokens[i]);
_totalTokens.increment();
}
}