The transesterification reaction is base catalyzed. Any strong base capable of deprotonating the alcohol will do (e.g. NaOH, KOH, sodium methoxide, etc.), but the sodium and potassium hydroxides are often chosen for their cost. The presence of water causes undesirable base hydrolysis, so the reaction must be kept dry.
In the transesterification mechanism, the carbonyl carbon of the starting ester (RCOOR1) undergoes nucleophilic attack by the incoming alkoxide (R2O−) to give a tetrahedral intermediate, which either reverts to the starting material, or proceeds to the transesterified product (RCOOR2). The various species exist in equilibrium, and the product distribution depends on the relative energies of the reactant and product.