When a butterfly or a moth enters into the point of their life when they wrap themselves into a cocoon, which is also known as a chrysalisis, it is time for them to start undergoing metamorphisis. During this stage in the butterly or moth's life, they do not eat or drink anything. Instead, they are in a type of hibernation that will last for anywhere from a few days to several months. There are some butterflies who go into their cocoon and stay there throughout the entire winter and then it emerges as an adult in the springtime.
A butterfly's cocoon is known as a chrysalis. This is a word that has been derived from the Greek word for gold. The cocoons of butterflies who belong to the Nymphalidae and Satyridae families are suspended from a silk pad that has abdominal hooks. On the other hand, Swallowtails and Sulphurs butterflies have a silk girdle that supports their mid-section. Approximately 1 day before the adult butterfly emerges, the cocoon of many species becomes transparent. An example of this is the Monarch butterfly.
Then there are moths. Some of them spin a silk cocoon which protects the pupa. Others tunnel into the ground up to several inches deep where it will pupate. These moth pupas (otherwise known as baby moths) have a cremaster at their abdominal (hind) end. These are either 1 or a cluster of small hooks that will then help the pupa get out of the ground or out of their cocoon.
In both cases, the cocoons of both butterflies and moths are pretty much the same. They are both made via the 2 glands inside of them that are filled with a thick glue-like material. This material is then pressed together as they emerge and then they harden in the air.