To prevent the frosting from melting, let the cupcakes cool completely before frosting them. You can also refrigerate the cupcakes for a few minutes before frosting them.