Yes, the earnest money is a good faith deposit that is held until the closing - and then is applied to the purchase amount. This helps secure the transaction, protecting the seller in case the buyer randomly decides to back out of the transaction.