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.