Can a Transaction Be Cancelled or Replaced Once It Enters the Mempool?
A transaction can be effectively cancelled or replaced while it is still in the mempool (unconfirmed) by submitting a new transaction with the same "nonce" (a sequential transaction count) but with a significantly higher gas fee. This technique is called "replace-by-fee" (RBF) or "cancel-by-fee." The network nodes will prioritize the transaction with the higher fee, effectively ignoring the original one.
If the new transaction is a zero-value transfer to the sender's own address, it acts as a cancellation.