Every transaction on the Ethereum network has a nonce. The Yellow Paper describes nonce as “A scalar value equal to the number of transactions sent from this address or, in the case of accounts with associated code, the number of contract-creations made by this account.” Each time a transaction is sent from the address, the nonce value for that next transaction is increased by 1.

This ensures transactions are mined in order. Transactions with a nonce number of 1 cannot be mined before a transaction with nonce 0. These nonce values prevents the double spending.

Canceling a stuck transaction on MetaMask with a nonce:

Step 1: Click on the top right corner profile picture and then on ‘Settings’.

Untitled

Step 2: Click on ‘Advanced’.

Untitled

Step 3: Scroll down and toggle ‘Customize transaction nonce’ to ‘ON’.

Untitled

Step 4: Send a new transaction (Either to the same address or to a different address) with the same nonce of the previous pending transaction.

Untitled

*** Credit to Sushi Samurai ***