1

I have a project where I am required to read and write to the same block ie.

  • Call a view function to check if there is a match on the specific block
  • If there is a match from the previous call, call a write function to confirm the match which is only on that specific block

By calling the view function, it ensures I don't have to pay gas fees until a match is actually found. When the match is made, we can then call the paid write function.

In the write function I have a line of code:

require(block.number == blockNumber)

blockNumber is passed in from the output of the view call (the block where the match has been made).

I cannot get this view function match to execute on the same block as the write function even though there is plenty of time to do so (after sending transaction, I check the block number and the current block is still the one expected).

The program making the calls to the contract is a C# program thats uses the Nethereum library.

I have tried the following:

  • Hard coded gas to be way above what's expected so I don't have to waste time calling the estimate for the write first
  • Given the write function an ungodly price per gas + the same for maxPricePerGas
  • Tried executing this on a very very fast machine

Does anyone know how I can solve this problem/is there something I am missing?

1 Answer 1

0

One way to ensure read and write in the same block is to execute both actions within the same transaction.

Another option is to use a flashbot service that will ensure both transactions are in the same block by "mining" in the same block.

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.