0

I want to make sure a number of transactions execute in a specific order while sending them all at once (preferably within a single block). Here's what the transactions look like:

  1. Fund ETH
  2. Interact With Contract
  3. Interact With Contract

2 is dependent on 1 running first and 3 is dependent on 2 running first.

It looks like I can guarantee this order using web3's batching. Can I or does the web3 batching just guarantee that this node will propagate the messages to the next node together only?

1

No, if they're separate transactions, it's up to the mining node's transaction ordering rules to determine if they all happen in the same block.

If you want atomic transactions, I'd recommend using a disposable, self-destructing contract to do the work for you.

Something like this:

contract AtomicInteraction {
  function AtomicInteraction() payable {
    // Fund ETH
    // Interact with Contract
    // Interact with Contract
    selfdestruct(msg.sender);
  }
}

You could probably make it even more generic, and have it accept an array of addresses and an array of data for each message, but that's a pretty complex solution for something that's probably going to require some application-specific logic anyway.

  • Can you show a reference for this information please? – 0xcaff Aug 16 '17 at 0:38
  • What if the wallet is the only thing authorized to interact with the contract? – 0xcaff Aug 16 '17 at 0:41
  • I don't have a reference for the batching information stuff... I just know that web3's batching API still resolves to individual transactions, which will be handled individually according to transactions are being orderd. More than likely they'll still be processed in the same order--what there are no guarantees about is whether or not they'll end up in the same block. If the wallet is the only thing authorized to interact with the contract... you might just have to be willing to risk that these things happen in different blocks... or delegate to the contract before executing – DeviateFish Aug 16 '17 at 0:46
1

you will need to write a custom await mined function that sends a new transaction based on the transaction receipt of the previous transaction by passing the transaction hash into web3.eth.getTransactionReceipt(), and rap this with a js setTimeout function based on the blocktime

  • This is what I ended up doing. – 0xcaff Jan 21 '18 at 19:33

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.