How can I set the tx ETH amount?

I know a user can send ETH to the contract/function manually, but is there way to request a specific amount directly in the code so that it is added to the gas fee, for example, the way dxsale.app does it when creating a presale (see screenshot below) - it adds the 0.1 ETH cost of presale to the 0.0072 gas fee for a total of 0.1072.

Can this be done in an ERC20 contract? I know I can receive ETH in a payable function, e.g.

    function deposit() payable public {
        require(msg.value > 0, "You need to send some Ether");
    }

but can I specify the amount I want to receive (for a flat fee), so that it is added to the tx cost?

Thank you

This is done by the dapp in JavaScript when they request the provider to sendTransaction. So it’s not something you can do in Solidity. Interesting question though!

1 Like