Gunpowder is a mixture of saltpetre, sulphur and charcoal that burns fiercely when lit. It was not found for the sake of war; the record of it comes from people making elixirs who were handling their ingredients.
In the mid-to-late Tang the Daoist alchemical text Zhenyuan miaodao yaolüe already recorded that mixtures of saltpetre, sulphur and other substances burst into flame and burned people. This is how gunpowder came to be found.
In the Northern Song the Wujing Zongyao recorded three military gunpowder formulas, and gunpowder formally entered military use.
After the conquest of Jiaozhi in the Yongle reign of the Ming, around 1407, the court set up the Shenjiying, a capital army unit specialising in the use of firearms in battle.
Gunpowder Weaponry is the class in the chapter on Sciences on gunpowder and the making of military arms. It covers the path from the Tang alchemical text that records saltpetre and sulphur mixtures burning, through the Northern Song Wujing Zongyao (Collection of the Most Important Military Techniques) with its three military gunpowder formulas, to the Ming Shenjiying, set up in the Yongle reign as a unit specialising in firearms.