Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question about repeat transactions #8

Open
MareoRaft opened this issue Sep 5, 2018 · 2 comments
Open

question about repeat transactions #8

MareoRaft opened this issue Sep 5, 2018 · 2 comments

Comments

@MareoRaft
Copy link
Contributor

This is more of a question for your sage advice than a feature request or bug report.

In my GUI, we want each transaction (tx) specified by the user to be separate. If the user specifies multiple payments to the same address, this is a problem because the network will interpret the second tx as redundant or as a replacement order (ref: https://ethereum.stackexchange.com/questions/27256/error-replacement-transaction-underpriced) if it is executed before the first transaction is completed.

My proposed solution is to check if there is a pending tx with the same from and to address as the new tx before submitting the new tx. When ready to send a new tx, the following will occur:

  1. Wait X seconds (maybe X = 15?) before checking, in case the old tx was just sent and the network wasn't updated yet
  2. Check the network to see if there is a pending tx with the same from and to address
  3. If no pending tx, execute. Otherwise, set a timeout of Y seconds (maybe Y = 20) to wait and then go to step 2

So my main question for you is do you know of a good way to check the network for pending transactions? I see that you wrote the awesome flex-contract library, and I'm wondering if that functionality is there. Thanks in advance for pointing me in the right direction!

@merklejerk
Copy link
Owner

You generally cannot have more than one pending transaction at a time. I say generally because with web3 or with the flex-contract library you can use a higher (by 1) nonce for each successive transaction and still broadcast them all at once, and what might happen is the node (in this case infura) will internally queue them up, broadcasting them in order as they confirm. This works sometimes but I wouldn't rely on it.

What you really have to do is maintain a queue yourself and execute them one at a time as they confirm.

Off the top of my head, I can't recall any web3 or rpc API for getting pending transactions given an address. Obviously the node knows this information so it might exist. But if you do know the transaction hash, you can definitely query its status with the web3 library, though even that can take some time for very new transactions to appear.

@merklejerk
Copy link
Owner

You can just wait on the promise returned by the library to wait for the transaction to be mined, FYI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants