The wax in the upper part of a candle melts because -
When a candle is lighted, the heat of the flame melts the wax near the wick. This liquid wax is then drawn up the wick. The heat of the flame vaporizes the liquid wax and turns it into a hot gas. These vaporized molecules are drawn up into the flame, where they react with oxygen from the air to create heat, light, water vapor (H2O) and carbon dioxide (CO2).