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

Concurrent transactions - replacement transaction underpriced rejection #1301

Closed
kwedrowicz opened this issue Jan 17, 2018 · 4 comments
Closed
Assignees

Comments

@kwedrowicz
Copy link

Hi,
I would like to send a few transactions from one account in a concurrent way (not wait with next until the previous one would be mined). When leaving setting nonce to web3js I get replacement transaction underpriced error. I can set defaultBlock as "pending" and then get nonce with web3.eth.getTransactionCount but until I explicitly set nonce I doesn't work either. Does web3js supports concurrent transactions like that? It's even more important with contract methods, but with sendTransaction I found a way to working example. I use version 1.0.0-beta27. From the docs I read that when nonce is not set, it's get from web3.eth.getTransactionCount() - why then this example doesn't work with web3.eth.defaultBlock = "pending"?

import { accounts, privateKeys } from "./utils/constants";
const Web3 = require("web3");


describe("Concurrent transactions", () => {

	before(() => {
		this.web3 = new Web3("https://ropsten.infura.io");
		this.web3.eth.defaultBlock = "pending";
		this.web3.eth.accounts.wallet.add(privateKeys[0]);
		this.web3.eth.defaultAccount = accounts[0];
	});

	it("should send concurrent transactions", async () => {
		this.web3.eth.sendTransaction({
			from: accounts[0],
			to: accounts[1],
			value: this.web3.utils.toWei("0.01", "ether"),
			gas: 100000
		}).on("transactionHash", async (transactionHash) => {
			console.log(transactionHash);

			const nextNonce = await this.web3.eth.getTransactionCount(accounts[0], "pending");

			this.web3.eth.sendTransaction({
				from: accounts[0],
				to: accounts[2],
				value: this.web3.utils.toWei("0.02", "ether"),
				gas: 100000,
				// nonce: nextNonce
			}).on("transactionHash", (transactionHash) => console.log(transactionHash));
		});
	});
});
@jdkanani
Copy link
Contributor

jdkanani commented Jan 22, 2018

Try commenting this.web3.eth.defaultBlock = "pending" and uncommenting nonce: nextNonce

@kwedrowicz
Copy link
Author

@jdkanani Of course this works in that way (that is the purpose of the snippet), but I'd like to know why it doesn't work with defaultBlock set.

@nivida nivida self-assigned this Aug 9, 2018
@nivida
Copy link
Contributor

nivida commented Oct 13, 2019

I'm closing this issue because increasing the nonce for locally signed transactions got implemented in 2.0.

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

4 participants