Begin by baking the pie shell if not already done; follow the instructions provided with your crust if pre-made. Allow the crust to cool completely before adding the filling.
In a medium-sized saucepan, combine the sugar, cocoa powder, cornstarch, and salt. Stir thoroughly to ensure even distribution of the dry ingredients.
Gradually incorporate the milk into the dry mixture while whisking to achieve a smooth consistency with no lumps.
Set the saucepan over medium heat. Whisk steadily as the mixture heats, continuing until it thickens and reaches a low boil, roughly 7 to 9 minutes.
Meanwhile, in a separate bowl, beat the egg yolks gently. Slowly stream about half a cup of the hot chocolate mixture into the yolks while whisking quickly to avoid curdling.
Transfer the tempered yolk blend back into the saucepan. Continue to cook over medium heat for an additional 2 to 3 minutes until the custard is thickened and uniformly smooth.
Remove the pan from the heat source. Stir in the butter and vanilla extract until the mixture is glossy and well-combined.
Carefully pour the warm chocolate filling into the pre-cooled pie crust. Use a spatula to level the surface.
Place a piece of plastic wrap directly on top of the custard to prevent a skin from forming. Chill in the refrigerator for a minimum of 4 hours, or until fully set.
To prepare the whipped topping, beat the chilled heavy cream along with the powdered sugar and vanilla extract using a mixer until soft peaks form.
Once the pie is thoroughly chilled and set, spread or pipe the whipped topping over the surface.
Finish with a flourish of chocolate shavings or a light sprinkle of cocoa powder, if desired. Slice and serve cold.