Grease an 8-inch/20cm springform tin.
Add the sliced potatoes to a large saucepan
Dissolve stock in hot water and add to the potatoes. Add more water until the potatoes are covered. Bring to the boil and then simmer until the potatoes are cooked but still holding their shape. Drain and leave to cool.
Add the butter to the flour until it resembles fine breadcrumbs. Add the grated cheese if using, and mix through. Slowly add the beaten eggs until it forms a dough ball.
Divide into 2 parts, one slightly bigger than the other and flatten into discs. Wrap in cling film and chill in the fridge for 30 minutes or 15 minutes in the freezer.
Meanwhile, place half of the butter in a frying pan and fry the chopped onions until soft. Drain and leave to cool.
Roll out the pastry discs starting with the larger disc until it's big enough to fit the base and sides of the tin leaving some overhang.
Layer the potatoes over the base of the pastry, then cover with the fried onions. Season with salt and pepper and add another layer and then a final layer of potatoes.
With the remaining butter, dot it on top of the potatoes. Fold any overhang of pastry down onto the potatoes and brush the edges with beaten egg.
Roll out the other disc of pastry. Lay on top of the butter and potatoes and press around the edge to seal. Brush with egg wash and make a hole in the centre so steam can get through.
Place the pie in the freezer whilst you preheat the oven to 160℃fan/180℃/350℉
Place the tin on a baking tray and bake in the oven for 40-45 minutes until golden brown.
Remove the outer ring and serve.