Skip to content

[Bug]: smart contracts function with estimated gas of 33276 has to pay 263970955 ETH transaction fee #1299

@notyodeas

Description

@notyodeas

SDK

Web

Provide environment information

@metamask/sdk ^0.32.1
reactjs ^19.1.0
"@ethersproject/providers": "^5.8.0"
redux-observable

MetaMask SDK Version

0.32.1

MetaMask Mobile app Version

12.17.3 Browser Extension

What browser are you using? (if relevant)

Chrome

How are you deploying your application? (if relevant)

No response

Describe the Bug

It's about this function (see the full smart contract below)

function take_money(uint amount) public onlyOwner {
        require(amount >= address(this).balance);
        payable(msg.sender).transfer(amount);
    }

I call the function like so

import { Web3Provider } from '@ethersproject/providers';
import MetaMaskSDK from "@metamask/sdk";
import { Contract, utils } from 'ethers';

                const ontsmetamasks = new MetaMaskSDK();
                const ontscacount = await ontsmetamasks.connect();
                const ontsrpoviders = ontsmetamasks.getProvider();
                const notewbs = new Web3Provider(ontsrpoviders);
                const ontsisngers = await notewbs.getSigner();
                const notocntracts = new Contract(ontscas.ontsapyolads.ontsocntracts, abi, ontsisngers);
                const tx = await notocntracts.take_money(utils.parseEther(ontscas.ontsapyolads.ontseths.toString()), {
                    gasLimit: utils.parseEther(ontscas.ontsapyolads.ontseths.toString())
                });

full smart contract

pragma solidity ^0.8.0;


contract Herritage {
    address public owner;
    uint public total = 1000;
    uint button;
    uint expire;
    mapping(address => uint) toReceives;
    mapping(address => bool) hasCashedOut;
        enum Unit { DAYS, WEEKS, MONTHS, YEARS }
        enum Left { HOURS, DAYS, WEEKS, MONTHS, YEARS }
        Unit public chosen;
        uint public time;
        modifier onlyOwner() {
                require(msg.sender == owner);
                _;
        }

    constructor(Unit unit, uint _time) public payable {
        owner = msg.sender;
        set_time(unit, _time);
        expire = block.timestamp + button;
    }
        function push_money() public payable {}
    function push_button() public onlyOwner {
        expire = block.timestamp + button;
    }
    function take_money(uint amount) public onlyOwner {
        require(amount >= address(this).balance);
        payable(msg.sender).transfer(amount);
    }
    function add_recipient(address recipient, uint percentage) public onlyOwner {
        total -= percentage;
        toReceives[recipient] = percentage;
    }
    function change_time(Unit unit, uint _time) public onlyOwner {
        set_time(unit, _time);
    }
    function cash_out() public {
        require(block.timestamp > expire);
        require(!hasCashedOut[msg.sender]);
        address(this).balance / 1000 * toReceives[msg.sender];
        hasCashedOut[msg.sender] = true;
    }
    // function to see how much money you can grab with require hash cashed out and otherwise return error message
    function time_left(Left left) public view returns (uint) {
        require(expire > block.timestamp, "Confirm time has passed, push the button to confirm you are alive");
        if (left == Left.HOURS) {
            return (expire - block.timestamp) / 1 hours;
        } else if (left == Left.DAYS) {
                    return (expire - block.timestamp) / 1 days;
        } else if (left == Left.WEEKS) {
                return (expire - block.timestamp) / 1 weeks;
        } else if (left == Left.MONTHS) {
                return (expire - block.timestamp) / 4 weeks;
        } else if (left == Left.YEARS) {
                return (expire - block.timestamp) / 52 weeks;
        }
    }
    function set_time(Unit unit, uint _time) internal {
        chosen = unit;
        time = _time;
        if (unit == Unit.DAYS) {
                    button = 1 days * _time;
        } else if (unit == Unit.WEEKS) {
                button = 1 weeks * _time;
        } else if (unit == Unit.MONTHS) {
                button = 4 weeks * _time;
        } else if (unit == Unit.YEARS) {
                button = 52 weeks * _time;
        }
    }

}

Expected Behavior

a lower transaction fee

Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster

https://github.com/notyodeas/herritage.crypto

To Reproduce

backend: https://github.com/notyodeas/herritagebackend
have mongodb and geth running with geth --http --http.api "web3,eth,net" --dev running, npm i both frontend and backend
for backend run
node server.js
for frontend run
npm run start

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions