0

This is the code I have for sending a transaction on Base Sepolia. I am using this to split the balance in my account into two halves and sending each half to an address one by one.

export async function sendTransaction(
  secretKey: string,
  amount: bigint,
  to?: string
) {
  try {
    const wallet = new ethers.Wallet(secretKey, provider);
    const gasPrice = await web3.eth.getGasPrice();
    const valueAfterGas = BigInt(Number(amount) - gasLimit * Number(gasPrice));

    const tx = await wallet.sendTransaction({
      to: to,
      value: valueAfterGas,
      gasPrice: gasPrice,
      gasLimit: gasLimit,
    });

    return tx;
  } catch (error) {
    log(`No transaction for ${amount} to ${to}`);
    errorHandler(error);
  }
}

While doing this I get the error -

replacement fee too low [ See: https://links.ethers.org/v5-errors-REPLACEMENT_UNDERPRICED ]

What can be the reason for this and how to resolve it? The gasLimit variable is set to 21000 as this is an address to address transfer.

4
  • Is your intention to simply send a transaction, or are you trying to increase the fee of an existing transaction? From what I can tell, they code you wrote is attempting to increase the fee of a previously created transaction. Since the original transaction was presumably created with the same fee, the EVM sees your request as "spam" because bumping the fee from 21000 to 21000 has no effect. TLDR: if you want to create an entirely new transaction you need to increment the nonce. If you want to bump the fee on an existing transaction, you need to increase the fee. Commented Mar 27 at 18:55
  • I need to send the entire balance of the account to another address. On ERC20 network this code does work but not on Base for some reason.
    – Zero
    Commented Mar 28 at 5:01
  • I am guessing that it works on the other network because there is no existing transaction with that nonce on that chain(so you aren't "bumping the fee" on that network you are just creating the transaction for the first time.) Commented Mar 28 at 15:51
  • The error is probably because L2 fees estimation is different from L1, any code you have?
    – Zero
    Commented Mar 28 at 15:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.