-
Notifications
You must be signed in to change notification settings - Fork 677
EVM errors with automine / Transaction Queuing #2338
Comments
You've almost got it set up correctly. If you omit the You can also send transactions with a nonce that is "too high" to Ganache v7, so you could fetch the transaction count just once on start up (depending on your use case you may need to check const nonces = new Map();
async function exchange(user, to, value) {
let currentNonce = nonces.get(user) || 0;
try {
const txHash = await sendTransaction(user, to, value, currentNonce);
nonces.set(currentNonce + 1); // transaction was accepted by Ganache
return await waitForReceipt(txHash);
} catch(e) {
// handle the case where the transaction could not be sent (like if the user doesn't have the funds to send the transaction)
}
} A said the above function "naive" because transaction monitoring can get pretty complex, especially when many transactions from a single account are in the transaction pool. You'll need to worry about sending "replacement" transactions (sending another transaction with the same
|
Closing for issue maintenance. |
i am building a centralised token exchange for ERC20 tokens with ganache-cli.
It's a simple order book system for trading, and each user has their own wallet on Ganache.
It works like this:
User sends order from frontend to backend NodeJS server > NodeJS sends order to ganache-cli > Ganache-cli sends result to frontend
It works quite well when one user makes an order for a token, however when multiple users make an order at the same time i get some errors on ganache-cli:
Error: Returned error: the tx doesn't have the correct nonce. account has nonce of: 4996 tx has nonce of: 4995
I'm generating a nonce and sending transactions like this:
My current settings are:
ganache-cli --database.dbPath /opt/db -a 20 --wallet.defaultBalance 100 --wallet.mnemonic "*" -g 0 -p 7545 --chain.networkId 987 -h 127.0.0.1 --miner.blockTime 0 --chain.hardfork berlin
Ganache-cli vesion:
ganache v7.0.1 (@ganache/cli: 0.1.2, @ganache/core: 0.1.2)
So my questions are
I would really like to solve these issues with Ganache directly, rather than building an order queuing system in between the frontend and Ganache!
Thanks
The text was updated successfully, but these errors were encountered: