The earliest appearance of a tanuki in Japanese folklore comes from the Nihon Shokai (The Chronicles of Japan), which deals mostly with Japanese mythology. It was written in 720, and the chapter about the Empress Suiko expressly mentions the tanuki: "in two months of spring, there are tanuki in the country of Mutsu, they turn into humans and sing songs." The tanuki also appears in the Nihon Ryōiki (written around 780 CE) and the Shūi Monogatari (written in the 13th century) — these works mention more of the tanuki's magical abilities: its shape-shifting, whether into human or animal forms, the ability to possess human beings, and its love of pranks.
[...]
Using their shape-shifting abilities, the tanuki will try and pass off leaves or scraps of paper as money in exchange for goods, and the ceramic statuettes are left outside restaurants and bars in particular, in an attempt to trick the tricksters into believing that they or one of their kind have already visited the store in question.