0

First of all I just started to tip my toes into smart contact development, so sorry if my question is not properly asked.

I want to participate in a pre-sale and to ensure my place I want to call the buy method of the contract at the block when the pre-sale starts. I found this:

myContract.methods.methodName().call(transactionObject, blockNumber, callback)

  1. Is this the way to do it with web3.js?
  2. Is it enough just to run a node server locally and put this function into a while loop?
  3. Am I right that the callback doesn't matter in this case?

Any resource to help me out is welcomed.

Thank you in advance

1
myContract.methods.methodName().call(transactionObject, blockNumber, callback)

No, it is not the way to do it. The block number in RPC methods is meant for historic purposes only, not to execute functions in the future.

What you need to do is to monitor the network, and when the block_number-1 will be announced, send your transaction expecting that on the next block (which is your desired block_number) it will be included. If you use high gas price it will be. But there is no guarantee as the block can be mined faster than your transaction propagating in the network. Because to propagate the block_number-1 there will be also some delay. Try to increase --maxpeers to 500 or around that so your node has more connections and gets more updated data.

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.