0

I'm trying to create a function in my smart contract that will invoke a payment from the user, for example when a button is clicked metamask will ask to confirm the 0.10 ETH payment to my contract, I understand payable functions and have tested this in remix and can pay my contract but I want to know how to 'invoke' a payment with a predefined amount of Ether and request it from the user. Thanks

1 Answer 1

1

Contracts cannot invoke transactions from Externally Owned Accounts (EOA) - as initiating transactions requires an (EOA) to sign with their private key. Not sure your particular application, but could it be solved with an escrow contract? As the user could send funds to an escrow to hold until the main contract required and then possibly be sent. Also, if you only want to accept transactions that carry a certain value, you would use:

function userSendsEth() {
     require(msg.value > someamount)
     //Any additional functionality
}
4
  • Thanks for that, would another option be sending Ether to the contract (done by the user) and using msg.value to check the amount they sent. If so how would they do this?
    – JAG
    Commented Jan 29, 2018 at 1:24
  • Yes, I updated the above, it would still require the user initiating the transaction - not the contract though. But it would ensure that the user sent whatever amount you specify as someamount.
    – Karen S
    Commented Jan 29, 2018 at 1:30
  • That's great, I have created a front end for my dapp. When the user goes to pay, how do they specify how much they want to send the contract?
    – JAG
    Commented Jan 29, 2018 at 1:36
  • You can include an input field for them to specify via the UI. Or if they are using MetaMask, they can include value input there as well.
    – Karen S
    Commented Jan 29, 2018 at 1:39

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.