Credit and debit cards are widely accepted in Sri Lanka, even in smaller towns. Visa and MasterCard are the most commonly accepted cards. American Express is also accepted, but to a lesser extent. That said, it’s still a good idea to carry some cash with you just in case.
You may also come across establishments that display their prices in US Dollars, especially in more touristy areas. While this is convenient, you should always make sure the transaction is performed in the local currency.
In Sri Lanka, it’s illegal to perform a card transaction in a foreign currency. In addition, if you choose to be charged in your home currency, the exchange rate will be determined using Dynamic Currency Conversion, not the mid-market rate. This almost always results in an unfavourable exchange rate.