Make the filling first. Boil potatoes until tender, mash them smooth, then mix with cheese, salt, and plenty of pepper. Set aside to cool—it firms up and makes wrapping easier.
Prepare the dough. In a bowl, whisk flour and salt. Add melted butter, water (and egg, if using). Stir to a shaggy dough, then knead on a lightly floured surface until smooth and elastic. Let it rest for about 30 minutes—this makes rolling easier.
Shape the dumplings. Roll dough to about 3 mm thickness. Cut into 3-inch circles, spoon a bit of cooled filling into the center of each, fold into a half-moon, and press edges firmly to seal. A dab of water on one edge helps seal them tight.
Cook the pierogi. Boil in salted water in batches. They’re done when they float—then fish them out gently and drain.
Optional frying. In a pan, melt extra butter, add onions and sauté until golden. Add boiled pierogi and fry for a minute until they get lightly crisp and coated with flavored butter.
Serve warm. Top with extra onions, a spoon of sour cream, bacon bits, or chives as you like.