What do butterflies eat?
Adult butterflies don't eat! I mean.... not in the sense of chewing on food. They rather drink. They get their nutrients via ingestion of liquid substances. Their mouth consists of a long tube called a proboscis that acts as a straw.

What do butterflies feed on?

The vast majority of butterflies eat nectar from flowers. Many species are quite specialized and feed on the nectar of a few species only.

There are a few exceptions though. Some species feed on tree sap, dung, mud (see mud-puddling), pollen, or rotting fruit. Butterflies are attracted to sodium and may as well try to feed on human sweat but I doubt there exist any species would get a non-negligible source of nutrients from human sweat. Coming to exceptions, you should definitely consider reading @DmitryGrigoryev's answer as well.

What do caterpillars feed on?

Of course, you are probably aware that butterflies have a complex (-ish) life cycle. The larva is called a caterpillar, while the adult is called a butterfly. So what do caterpillars eat?

Caterpillars have mandibles, so they can chew tissues and not just drink. Most caterpillars eat leaves and other plants parts. Again, many species are specialized to only a few plant species.

There are of course exceptions. For example in the Phengaris genus, (such as the famous large blue (Phengaris arion), caterpillars live in ant colonies and mimic the larvae of these ants. Some of them are able to trick the ants into feeding them as though they were ant larvae (e.g. Phengaris alcon, Phengaris rebeli). Others (e.g. the aforementioned Phengaris arion) will act as predators and eat the real ant larvae!

When the butterflies emerge from their cocoons after metamorphosis, the ants finally figure out the trickery and start attacking the butterfly. The butterfly has therefore very little time to try to fly away from the colony before getting killed. It is a critical life stage for individuals of this species.

How to feed a butterfly?

This section exists thanks to @Rodrigo's recommendation.

As a substitute of nectar one can simply use sugar water. The optimal sugar concentration (in mass-mass) is around 35% (Kim et al. 2011) although it likely varies among species.

Kim et al. 2011 explains that what limits optimal sugar concentration for insects is the viscosity of the solution. Too much sugar renders the solution too viscous and difficult to forage on. Interestingly, the ability to drink viscous solutions depends upon the drinking technic (active suction, capillary suction or viscous dipping) which vary, not among butterflies but among insects. The article is interesting.