Even moist sand or dirt often has enough liquid nutrients that the butterfly can get the nutrients it needs. Sometimes even rotting animal flesh will provide the butterfly with food.
If you are out working or playing on a hot day often a butterfly will land on you and drink from your skin. It is drawn to your skin by the salt in your sweat. Sweat has salt, and other minerals that butterflies need.