Unexpected behaviour for multiple contract interactions
Hi there,
when trying to send multiple transactions at once to call methods of a contract, all previous transactions seem to be overwritten by the last one sent and the result are multiple executions of the same method.
Example code for reproduction:
const HDWalletProvider = require('@truffle/hdwallet-provider')
const Web3 = require('web3')
const web3 = new Web3(new HDWalletProvider(private_key, provider))
const contract = web3.eth.Contract(contract_abi, contract_address)
contract.methods.abc(data1).send(transaction)
contract.methods.xyz(data2).send(transaction)
As a workaround, one can Increment the nonce manually in the transaction data. In this case the method executions work fine. Unfortunately, it takes multiple seconds to get the current nonce back with await web3.eth.getTransactionCount(my_address). Can you guys propose a faster solution or do I need to change something in the setup?
Interestingly, when sending multiple ETH transactions, this works fine with the following code, which makes me wonder what might be the underlying issue:
web3.eth.sendTransaction(transaction1)
web3.eth.sendTransaction(transaction2)
Best wishes
To clarify it a bit: When e.g. sending 3 different transactions to the same contract, 3 equal transactions are executed, as if the last transaction would have been sent 3 times.
Update: Even if I interact with the contract interaction via encodeABI() and sendTransaction, I get the same bug as well as if I send from two different accounts to the contract. Does anybody has a clue where this is resulting from?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.
Did you ever fix this?
Not so far, I am now just acquiring the nonce once and then manually increment it, which works quite fine for my applications
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.