0

I am looking for a way to create a contract that reacts according to User Input. For my purpose it would be awesome to somehow "wait for a users input" and as soon as this is done automatically continue by executing a contracts function according to the user input. Now I know that "waiting loops" arent possible in functions because the transaction would simply run out of gas.

Is there any other way to solve this problem? The pattern I want to use is: "Execut contract A, during A ask User for input, continue A automatically as soon as the contract receives the users input"

Many thanks!

Edit, More general explanation of the problem: Contract A provides a function. If a User wants to interact with the contract he call the function and gives the required arguments. At some point the function might ask the user for some additional information like an additional Uint-Value or String-Value. Now what I want is that the original contract function resumes doing its computation as soon as the user gives additional input

Any ideas for a pattern like this?

  • IMO, while it is not impossible to do something almost as described, it is almost certainly not how you want to handle the flow. It's hard to say what a better solution will look like without more specific details. If you can describe the requirements in a way that's open-minded about the solution, someone will probably chime in with a more EVM-oriented solution. – Rob Hitchens - B9lab Sep 7 '17 at 14:01
  • Good point! I ll try to give a more open-minded explaination of the problem. I ll edit my original question for that reason – CaptainMNB Sep 7 '17 at 15:03
1

I think the pattern here will be:

  • User client invokes contract function
  • Contract executes first part of the code
  • Contract raises event DataRequired (User client is subscribed to this event already)
  • Client collects input and invokes another function which completes the process
  • What exactly do you mean with "Contract raises event DataRequired (User client is subscribed to this event already)" ? Whould you realize this using an Event? – CaptainMNB Sep 7 '17 at 14:34
  • I think that's exactly what he meant, yes. Firing an event after the first interaction will let your application know when to prompt the user for the input. – simonDos Sep 7 '17 at 14:40
  • Okay great, one step closer to what I want to achieve! But can you give me a short example? I just started to learn about events. Can I trigger functions from events? – CaptainMNB Sep 7 '17 at 14:48
1

@Strelok's answer is helpful. I would be more opinionated because it might help clarify thinking. In my opinion the two-way dialog about formation of a single transaction suggests a failure to separate concerns.

For a working mental model, consider the smart contract design as similar to an API design, with requests either valid and processed (Yes, Ok) or not acceptable (No, nothing happened). There is no "Yes, but I need more information."

If the initial request is valid (insert, update, transfer) then accept it. If the request is incomplete, then reject it (error).

The correct way to break transactions down into atomic events that either complete entirely or not at all tends to move concerns around in ways that take some getting used to.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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