Take Smaug for example. A dragon guarding large a large amount of gold. When did this narrative start and what was the reason for it?
Tolkien took his inspiration for Smaug, a gold-coveting dragon rather directly from the Anglo-Saxon poem, Beowulf, where a thief steels a golden cup, inspiring the deadly tirade of the monster. This places the motif as far back as the early Middle Ages, where it appears in Old English literature fully formed as though it may have circulated before literacy.
An early documentation of a similar motif occurs with the monster guarding the Golden Fleece, which was taken Jason and the Argonauts. This places the motif several centuries before the Common Era. A similar – though later – expression of a dragon-like monster and gold appears in accounts Fafnir, who was killed by the hero Sigurd in various Germanic/Scandinavian pieces of medieval literature.
These examples point to a widespread idea of a large serpentine monster, often with poisonous breath attracted to and protecting his hoard of gold. The hero overcomes this creature in most stories.
I refer here to a “large serpentine monster” rather than a dragon because it easy to be sucked into a mental image as soon as the word “dragon” is used. These monsters are tied – thematically and likely historically – to one another, but they weren’t winged, fire-breathing dragons as Tolkien described and the modern imagination projects. These monsters often did not fly, and fire was not always present. Instead, the venomous nature of their breath was withering, something that would eventually transform into fire.
The widespread nature of this motif suggests a pre-literate folk tradition of a popular fascination with gold and the greed it could inspire. This gold-driven motif was apparently often linked with the motif of the serpentine monster. Although the monster could be very old – older than the motif of the golden hoard – we can only imagine the motif of the gold hoard being as old as working with precious metal.
Sadly, because much of this early development of the motifs likely occurred before literacy, it is undocumented, and we can only speculate about its origin and early development. This was not, however, a literary development – at least initially. It was a matter of folklore that later manifested in literature where sources may or may not have influenced one another even as they drew on similar oral traditions.
Edit: thanks for the award; is that a dragon? It looks like it and I am very pleased if that is the case!
edit #2: A Three-Headed Dragon - with a pile of silver. These awards are becoming their own folktale. I love it! Thank you!
The short answer is that the idea of dragons guarding treasure appears to be older than the idea of dragons loving treasure. The notion that dragons are obsessed with treasure seems to have arisen in classical antiquity or earlier as one of several different explanations for why they guard it. Due to various circumstances, this explanation has now become accepted as standard in western popular culture.
The word dragon comes from the Ancient Greek word δράκων (drákōn). The ancient Greeks typically imagined drakontes (which is the plural form of drakōn) as essentially giant serpents. In ancient Greek mythology and literature, drakontes are primarily said to serve as guardians. The word δράκων itself comes from the partially deponent verb δέρκομαι (dérkomai), meaning "to watch," indicating a creature that watches over something and protects it.
In many Greek myths, drakontes are specifically said to guard treasure. For instance, in a myth that is first attested by the Greek poet Hesiodos of Askre in his narrative poem Theogonia, lines 333–335, which most likely became fixed in something resembling its extant form sometime in around the early seventh century BCE, the multi-headed drakōn Ladon is said to guard a tree with golden apples in the Garden of the Hesperides. One of the Twelve Labors of Herakles is said to have been to retrieve these apples.
Meanwhile, in the myth of Iason and the Argonauts, a drakōn is said to guard the Golden Fleece in the land of Kolchis. A very famous tondo from an Attic red-figure kylix painted by the vase-painter Douris at some point between c. 480 and c. 470 BCE (a photo of which you can view here) depicts the Kolchian drakōn disgorging Iason as the goddess Athena watches. The myth of the Kolchian drakōn regurgitating Iason is only attested in the Douris kylix, but the myth of it guarding the Golden Fleece is also retold in numerous ancient Greek literary sources, including the Hellenistic epic poem Argonautika, composed by the Greek poet Apollonios of Rhodes in the third century BCE.
Treasure, however, is not the only thing that drakontes in Greek myths guard. They are also commonly said to guard springs and bodies of water. In the myth of Kadmos, for instance, a drakōn that is sacred to Ares is said to guard the Ismenian spring, where Kadmos's companions go for water. The drakōn kills Kadmos's companions and Kadmos, in turn, slays the drakōn.
Ancient Greek and Roman sources disagree about why drakontes seem to guard treasure so much. One ancient explanation holds that drakontes don't actually care about treasure, but they guard it because the deities require them to.
For instance, an Aisopic fable told by the Roman fabulist Gaius Iulius Phaedrus (lived c. 15 BCE – c. 50 CE) in his Fables 4.20 claims that a fox digging its burrow once accidentally found a drakōn guarding treasure in an underground lair. The fox asks the drakōn what he gains by guarding the treasure. The drakōn replies that he gains nothing, but he must guard the treasure anyway because Zeus has imposed the task on him. The fox then draws the moralizing conclusion that human misers are like the drakōn because they are both born under the curse of angry deities.
Another ancient interpretation, however, holds that drakontes have an innate love for golden treasure and that this is the reason why they guard it. For instance, the Greek sophist Philostratos the Elder (lived c. 190 – c. 230 CE) declares in his Imagines 2.17.6 that the drakōn that supposedly guarded the Athenian Akropolis remains there because it loves the golden cicada brooches that the Athenians traditionally wear in their hair. He writes (as translated by Daniel Ogden): "for this creature is said to be keen on gold, and to love and hug close whatever golden thing it sees."
As u/itsallfolklore explains in their answer to this question, the explanation that drakontes guard treasure because they are obsessed with gold eventually found its way into the early medieval epic poem Beowulf, which was composed mostly in the West Saxon dialect of Old English at some point between c. 700 and c. 1000 CE. In that poem, a treasure-loving dragon is guarding a hoard in its lair at Earnanæs. After a slave breaks into the lair and steals a jeweled cup, the dragon notices that the cup is missing and goes on a rampage, burning all the surrounding homes and farmland. This leads the hero Beowulf to go to the dragon's lair to slay it.
J. R. R. Tolkien was the Rawlinson and Bosworth Professor of Anglo-Saxon at Oxford University and he was closely familiar with the poem Beowulf. As such, he drew heavy inspiration for the dragon Smaug in his children's fantasy novel The Hobbit, originally published in 1937, from the dragon in Beowulf. As a result, the idea that dragons are obsessed with treasure has become the standard explanation for why they hoard treasure in contemporary western popular culture, even though this is not the only explanation that existed in antiquity.
For more information about drakontes in ancient Greece and Rome, I highly recommend the book Drakōn: Dragon Myth and Serpent Cult in the Greek and Roman Worlds by Daniel Ogden, published in 2013 by Oxford University Press. I especially recommend the chapter "Treasure without, treasure within" (pages 173–178), which discusses the idea of drakontes hoarding treasure in ancient Greek and Roman myth.
Tolkien was heavily inspired by Norse Mythology. I see Beowulf has been mentioned, but a more obvious origin comes from the story 'The Otter's Ransom'. This was the same story that would also inspire C.S. Lewis for the tale of Eustace in "The Silver Chair", by the by. It's also one of my favourites.
One source is from Snorri Sturluson (who should always be taken with a grain of Christianized salt) in Skáldskaparmál, which can be read in full here, or can be summarized by me in more humourous form thusly:
Like many great Norse Myths, the conflict begins when Odin and Loki go out for a walk. And as per usual, It doesn't take long for Loki to screw everything up. This time he does it by throwing a stone at an otter, killing him, and taking the dead thing with him to be fashioned into something nice for him to wear. (You'd think that Loki, being a shapeshifter himself in some stories, would know better. Or at least Odin would. They should have some kind of system.)
Tough luck, because it turns out the otter was a shapeshifter named Otr/Ottär. And as Loki's luck would have it, he and Odin walk right into Ottär's family home. Dear old dad, Hreidmar, and Ottär's siblings, Fafnir and Regin, don't much approve of Loki's new fashion statement and demand recompense, or else they'll use their magics to trap Odin and Co. forever. Said recompense: Cover Ottär's otterskin with gold. Every. Square. Inch.
Odin is kept hostage while Loki is sent out to acquire the gold. Luckily, Loki's pretty good at messing with dwarves, which is a lucrative affair. (Unluckily, they're even better at messing back with Loki. And by messing back, I mean torturing.) Loki went looking for the dwarf, Andvari, another shape-shifter, and found him disguised as a fish in a pool. In a move that will be hilarious to any other Loki fans out there who know how this will eventually go down for him, Loki invents a fishing net and catches Andvari in it. He offers to release Andvari only if the dwarf will give him enough of his treasure to cover Loki's Werguild (blood money debt) to Ottär. This, the dwarf does. However, the dwarf declares that one part of the treasure is forever cursed to bring ruin to any who possess it - the ring Andvaranaut. (By the by, this is most likely the inspiration for the One Ring in LOTR as well.) The name means Andvari's Gift, although the story hints that it was not his curse upon it, but a more ancient one.
Loki returns and shows Odin the treasure. Odin removes the cursed ring, but places all the rest of Andvari's treasure gold upon Ottär's pelt. The gold completely covered the otterskin - but Hreidmar pointed out that a single whisker remained goldless, and demanded that, too, have gold placed upon it. Odin then places the cursed ring upon the whisker, deciding that if Hreidmar were so greedy as that, then he was welcome to the ring and all it brought with it.
The gods then skeddadle, no doubt wanting to watch what happened next from the high seat of Asgard, which has the best views. Andvaranaut's curse soon took effect. The ring exerted a powerful force that compelled anyone near it to want to possess it at any cost. (Sounds familiar, no?) This temptation eventually drives Hreidmar's sons, Fafnir and Regin, mad with greed. The two slay their father and take all the weirgold for themselves, but when it comes to who should keep the ring itself, Fafnir turns against his brother and threatens to kill him as well. Regin flees, and Fafnir takes possession of all the treasures.
Now, this part is a bit different between versions - some have it that Fafnir transfigures himself into a dragon to protect his wealth, and others have it that it is the curse of the ring itself that slowly transfigured him into a wyrm, which is the version that would inspire Lewis with the character of Eustace. (And perhaps Tolkein as well, with the degradation of Smeagul and the Ring Wraiths, who were also consume and transfigured by their rings.) In any case, Fafnir the Dragon is indubitably one of oldest depictions of a 'greedy dragon upon a pile of gold', and can be directly connected to two prominent examples that perpetuate that image in modern fiction, being Smaug from The Hobbit, Eustace from The Silver Chair, and everything hence inspired by that.
Fafnir would go on to be slain by Sigurd, a very influential Norse hero, and from that imagery comes a lot of what you'd know of dragon-slaying iconography as well.
So, in short - Fafnir is probably one of the oldest 'greedy dragons' around, and probably what you're looking for.
Another dragon to look at would be Nidhogg, the dragon eating the roots of Yggdrasil. He's often depicting as standing on a mountain of bodies and is called 'Corpse-Eater'. If Fafnir represents greed for wealth, then Nidhogg is insatiable appetite for conflict and eventual total destruction, as he desires to consume the universe entirely.