I had do some transaction in Binance Smart Chain in Binance-Peg BUSD-T and it worked successfully. But after 5 transactions. I face to a problem that said Returned error: transaction underpriced
! This is my code:
const web3 = new Web3('https://bsc-dataseed1.binance.org:443');
const contract = new web3.eth.Contract(abi, usdtContractAddr, {
from: 'SENDER_ADDRESS', // default from address
gasPrice: '200000000' // default gas price in wei, 20 gwei in this case
});
web3.eth.accounts.wallet.add('SENDER_PRIVATE_KEY');
const receipt = await contract.methods.transfer('TO_ADDRESS', '1000000000000000000').send({
from: 'SENDER_ADDRESS',
gas: 100000
});
I have increased my gas 10% and add a nonce more than the value which was given to me by calling
web3.eth.getTransactionCount('ADDRESS')
. But non of them works. I used to do a lot of transactions in Binance-Peg BUSD-T and so it is a big problem for me. Is there a way to solve this problem ???
The "transaction underpriced" error occurs, when you're trying to replace a transaction and the replacing gas price is too low.
web3.eth.getTransactionCount()
only returns the amount of mined transactions. But you can have N (not just one) of transactions that are waiting to be mined with already higher nonce.
Example:
getTransactionCount()
returns 2Solution:
Use even higher gas price if you want to replace the existing transaction.
Or if you want to submit a new transaction (and not replace the previous), use higher nonce (sum of "successfully mined" + "waiting to be mined" + 1) that your address haven't used.