Butterflies do not build cocoons, they lay their eggs directly on the leaves of their food plant either as solitary eggs or in clusters. Usually they do this on the underside of the food plant leaves.
The caterpillars hatch out of the eggs and begin to feed on the food plant growing all the time and shedding their skins as they do so.
Finally when they are full size, they will crawl away form the leaves and using a sticky silk thread which they produce form their mouth area, they will anchor themselves to a secure branch and shed their skin once more. This time when the old skin comes off the new body sheath will be a covering called a chrysalis which will hang from the silk thread. This is the pupal stage of the caterpillar's life cycle.
Inside the pupa the caterpillars organ's liquefy and reform to the body shape of the adult butterfly and after this process is complete the pupa cracks open, the adult butterfly crawls out and pumps up its wings to remove the crumples and dry the wings.