0

In ETH could you call a contract by inputting a variable parameter? As in the value of that parameter is unknown at call and must be evaluated at run-time?

Something like "someFunction( current_time_at_run_time );" - is this allowed?

Thanks.

3
  • 1
    I am afraid it is not possible, you need in the body of the function the call to the now() function for your particular case
    – Briomkez
    Oct 14, 2018 at 19:51
  • You should be aware that now() is the timestamp of the block, it is established once for block and therefore all transactions in the block share the same timestamp. So, it may not always be precise. Moreover, It can be controlled to a certain degree by the miner (it should be definitely not used as a seed for random calculation!)
    – Briomkez
    Oct 14, 2018 at 20:10
  • Thanks, that was just used as an example, I'm not trying to do anything specific just wondering about the constraints.
    – reedvoid
    Oct 15, 2018 at 3:06

1 Answer 1

1

You can't make the EVM interpolate things in the parameters you supply in your transactions. The code creating your transaction, typically JavaScript, can of course do whatever computations it likes to create the parameters, but in your case the time the transaction is created won't match the time it's executed (mined).

What you can do is wrap the call in another contract, and have the outer contract do the interpolation you want.

contract Inner {
  function someFunction(uint timestamp) {
    // do something with that timestamp
  }
}

contract Outer {
   function callInnerWithCurrentTime(address inner) {
     Inner(inner).someFunction(now);
   }
}

Your Answer

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

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