A universally accepted commodity
For coins to appear the society must first reach a stage where there is a universally accepted commodity.
In the beginning trade was done in the form of barter, that is, goods and services were exchanged directly for other goods and services. Barter is inefficient. For example, suppose that a person P has three dozen eggs and wants two cubits of cloth. They must find another person who has cloth and wants eggs. If there is no person who has cloth and wants eggs, they must inquire what do the cloth-having persons want? Maybe a person Q has cloth and wants amphoras. So now person P must find a person R who has amphoras and wants eggs, so they can exchange the eggs for amphoras and then go and exchange the amphoras for cloth. Barter slows down trade considerably.
During the Late Bronze Age the civilizations in the eastern Mediterranean and the Levant reached the stage where trade began to use a generally accepted commodity, in the form of metal -- initially iron, copper or bronze. Everybody accepted metal, by weight, and trade was considerably simplified; for example, see the Greek obols, which were originally spits of copper or bronze traded by weight. The use of iron, copper or bronze as a generally accepted commodity was a great progress, but it was still inefficient because these metals are quite common and therefore traders needed to carry large amounts of them.
Standardized pieces
The next step forward was to use rarer metals -- silver and gold -- as a generally accepted commodity. In his Histories, Herodotus writes that the Lydians, a people in what we call today western Anatolia, "were the first men whom we know who coined and used gold and silver currency, and they were the first to sell by retail" (Histories, book I, chapter 94, trans. A. D. Godley). The advantage of using standardized pieces is that they can be counted, eliminating the need to assay them and weigh them, thus facilitating trade. Coins were invented roughly simultaneously in the Mediterranean, India and China; the oldest Lydian coins date from the late seventh - early sixth century BCE.
From the physical coins -- standardized pieces of metal -- came the idea of an abstract unit of value, laying the foundations for accounting and enabling the states to set up efficient taxation.
Centralized mints
Since coins were so much more convenient than using metals by weight, the states, be they kingdoms or republics, found a great source of revenue. They established centralized mints and required that metal be converted into coins only in the state mints; the mints charged a fee for this service (seigniorage). The coins made in the state mints were stamped with state symbols, guaranteeing their weight and purity.
As an aside, the first Roman mint was set up in the temple of Iuno Moneta (Juno the Mindful); from the Latin words moneta and monetalis comes the English word monetary, and indirectly the words money and mint.
Counterfeiting and further consequences
With the invention of coins came counterfeiting -- see a gallery of ancient counterfeit and imitation coins. With counterfeiting came a need to detect and apprehend counterfeiters, and a need to assay the coins accepted in trade. The ancients used various methods to assay the purity of coins, for example touchstones and measurements of density.
Since each and every little city state made its own coins, a need appeared for professionals who specialized in exchanging one kind of coin for another.
Once the minting of coins became a state monopoly rulers naturally found that they could increase their apparent revenue and purchasing power by minting coins with less precious metal in them than their face value; the unfortunate consequences of debasement are endlessly met with in history from the Antiquity to the Modern age, up until commodity money was replaced with fiat money (and debasement was replaced by inflation).