1

I'm trying to have a function generate a request such that it pops up a Metamask request.

I know I can do: require(msg.value == amount); to require the function call has a certain value.

But this requires the transaction sender to manually input the transaction value which is error prone or they may not know the value to send. I want the contract to request a certain amount so that the user only needs to accept the transaction in Metamask.

In psuedocode, something like "request X ETH from msg.sender"

Thanks.

1 Answer 1

3

The contract can't prompt the user for any input. It has to be the frontend code which asks the user for input.

So in your frontend you need to ask the user to input the amount of Ether to send and then you can use that amount in the value field for the transaction. Examples can be seen here: https://web3js.readthedocs.io/en/v1.2.11/web3-eth.html#id86

1
  • Unfortunately it does seem I can't do this in the contract and need to use web3js in the UI, thanks.
    – gmondok
    Commented Oct 13, 2020 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.