In your docs it is stated that in order the get protection against uncled blocks, the following check should be included in the smart contratc function or transaction:
require(blockhash(block.number - 1) == expectedParentHash, "block was uncled");
My question is: where do I source the expectedParentHash? How can I implement this correctly? As far as I know, expectedParentHash is not a global variable. How can I make my contract find the right one?
I am sorry. I am afraid I did not convey the doubt correctly.
I know how to search for the last block hash (for instance in the block explorer). My question is how to implement that variable in the contract I want to make the frontrunning-safe call to. Obviously, it cannot be hard coded in it, since it first has to be deployed and AFTERWARDS, in a later block, called upon, so the expectedParentHashis unknown at the time of deployment.
It can be an input of the called function, together with all the other parameters. But this method would require to keep an eye on the block explorer, grab the hash as soon as a new block is produced and run to input it in my transaction hoping I still make it on time before a newer block is produced. Is this the case or am I missing something? Can you please provide a sample / guideline of how this has been implemented?