An account of the origin of Mjölnir is found in Skáldskaparmál from Snorri’s Edda: In this story, Loki bets his head with Sindri (or Eitri) and his brother Brokkr that they could never succeed in making items more beautiful than those of the Sons of Ivaldi (the dwarves who created other precious items for the gods: Odin’s spear Gungnir, and Freyr’s foldable boat Skíðblaðnir).
Sindri and Brokkr accept Loki’s bet and the two brothers begin working. They begin to work in their workshop and Sindri puts a pig’s skin in the forge and tells his brother never to stop working the bellows until he comes and takes out what he put in. Loki, in disguise as a fly, comes and bites Brokkr on the arm. Nevertheless, he continues to pump the bellows.
Then, Sindri takes out Gullinbursti, Freyr’s boar with shining bristles. Next, Sindri puts some gold in the forge and gives Brokkr the same order. Again, Loki, still in the guise of a fly comes and, again, bites Brokkr’s neck twice as hard as he had bitten his arm. Just as before, Brokkr continues to work the bellows despite the pain. When Sindri returns, he takes out Draupnir, Odin’s ring, which drops eight duplicates of itself every ninth night.
Finally, Sindri puts some iron in the forge and tells Brokkr not to stop pumping the bellows. Loki comes a third time and this time bites Brokkr on the eyelid even harder. The bite is so deep that it draws blood. The blood runs into Brokkr’s eyes and forces him stop working the bellows just long enough to wipe his eyes. This time, when Sindri returns, he takes Mjölnir out of the forge. The handle is shorter than Sindri had planned and so the hammer can only be wielded with one hand.
Despite the flaw in the handle, Sindri and Brokkr win the bet and go to take Loki’s head. However, Loki worms his way out of the bet by pointing out that the dwarves would need to cut his neck to remove his head, but Loki’s neck was not part of the deal. As a consolation prize, Brokkr sews Loki’s mouth shut to teach him a lesson.
The final product is then presented to Thor, and its properties are described, as follows,
Then he gave the hammer to Thor, and said that Thor might smite as hard as he desired, whatsoever might be before him, and the hammer would not fail; and if he threw it at anything, it would never miss, and never fly so far as not to return to his hand; and if be desired, he might keep it in his sark, it was so small; but indeed it was a flaw in the hammer that the fore-haft was somewhat short.
— The Prose Edda, translated by Arthur Gilchrist Brodeur (1916).