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.
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityYou 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);
}
}
now()
function for your particular casenow()
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!)