MA is a 2 contract purchase process but it may be different if you are buying in another State.
I hope that helps!! Hire a good exclusive buyers agent to walk you through the process. If you work with the listing agent they will be very limited on what advice they can give you.
You need to speak to you attorney regarding possible outcomes. There is an offer to purchase and then a purchase and sales contract.
Yes, sellers ask for an Ernest Money Deposit (EMD) when you submit your offer. This is usually 1%-2% of the purchase price (but you can do any amount you want to). As long as you have contingencies included in your offer and you do not remove them in writing, you should get your full EMD back if you cancel contract - as long as the reason you cancel is an acceptable one per your purchase contract.
And if you mean an earnest money deposit.
It's just the same as a non-contingent offer. You make an offer accompanied by an earnest money deposit. The only difference with a contingent offer is that you have some additional "outs." In a non-contingent offer, for instance, you'd be expected to go through with the purchase even if you weren't able to obtain financing. If your offer is contingent on obtaining financings--and you aren't able to--then the deal is called off.
However, to oversimplify a bit, you get your money back if the reason for your not buying is: (1) the fault of the seller, or (2) covered by one of the contingencies. But you can't just "change your mind." Example: You make an offer accompanied by a $2,500 earnest money deposit. The seller accepts your offer. You're approved for financing; the house appraises for the sales price. Then you get cold feet and just want to back out. In that case, your earnest money deposit is at risk.
Check with your Realtor for more details.
Hope that helps.