Gunpowder is a type of chemical explosive, a mixture of sulfur, charcoal, and potassium nitrate (saltpeter). It is the first invented chemical explosive and was the only one until the middle of the 19th century. Its uses are predominantly a propellant in firearms and a pyrotechnic composition in fireworks.
Gunpowder was invented in China by alchemists who tried to find elixir of immortality. Since 492 Chinese alchemists knew that saltpeter burns with a purple flame but the first mentioning of the gunpowder dates from the mid-9th century, during the Tang Dynasty, in a Daoist work “Zhenyuan miaodao yaolüe”. Earliest formula for gunpowder dates from 1044 and is written in “Wujing Zongyao”, a Chinese collection of military information. From the same text comes the first gunpowder weapon - fire lance or fire spear that was a type of gunpowder-fueled flamethrower. Gunpowder was also used for fireworks whose role was to scare away evil spirits. By 989, Chinese invented fire arrows tipped with explosives and by 1000 - flamethrowers. In time, gunpowder manufacturing was perfected and by 14th century Chinese had discovered how to create explosive round shots from which canons were developed.
Genghis Khan used a Chinese specialist catapult unit in battle that hurled gunpowder bombs and that is how Arabs acquired knowledge of gunpowder by the end of the twelfth century or the beginning of the thirteenth. Mongols also used huochongs, a type of Chinese mortars. The first cannon in history was used by the Mamluks against the Mongols at the Battle of Ain Jalut in 1260. Rockets were also popular and the first torpedo appeared at about the same time. The first portable firearm and a forerunner of the handgun was a hand cannon which appeared in several Arabic manuscripts dated to the 14th century. At the same time, and also probably with Mongols, gunpowder arrived to India and became prevalent form of warfare.
Gunpowder came to Europe in one of the two ways: along the Silk Road or during the Mongol invasion in the first half of 13th century. For the first time in Europe, gunpowder is mentioned in 1267 and gun in 1326. The first guns used in Spanish empire, Ottoman empire, Portugal and in Japan were arquebus - early muzzle-loaded firearm used in the 15th to 17th centuries. It had matchlock which ignited the gunpowder. During the Renaissance two European schools of pyrotechnic thought emerged, one in Italy (which worked on elaborate fireworks) and the other at Nürnberg, Germany (which worked on scientific advancement).
Gunpowder was also used in mining and tunnel and canal construction. For the first time gunpowder is used in mines in Hungary in 1627. German miners brought it to Britain in 1638 after which its use spreads. It was very dangerous to use gunpowder to break rock until William Bickford invented the safety fuse in 1831. The first larger use of gunpowder in civil engineering was in the construction of the Canal du Midi in Southern France. Canal was 240km in length; it linked the Mediterranean Sea with the Atlantic and was finished in 1681. Tunnel construction also benefited from gunpowder and with it railways.