Preheat oven to 350°F (175°C). Grease a 9x13-inch baking pan.
In a large bowl, whisk together flour, sugar, baking soda, and salt.
In a saucepan, melt butter with water and cocoa powder, stirring until smooth. Remove from heat.
Pour the chocolate mixture into the dry ingredients and mix well.
Add eggs, sour cream, and vanilla, mixing until fully combined.
Pour batter into the prepared pan and bake for 18-22 minutes, or until a toothpick comes out clean.
While the cake bakes, melt butter with cocoa powder and milk in a saucepan. Bring to a boil, then remove from heat.
Stir in vanilla and powdered sugar until smooth.
Fold in chopped pecans (if using).
Pour the warm frosting over the hot cake as soon as it comes out of the oven.
Spread evenly and let cool before slicing.