The transesterification reaction is base catalyzed. Any strong base capable of deprotonating the alcohol will work (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 (RCOOR) undergoes nucleophilic attack by the incoming alkoxide (RO) to give a tetrahedral intermediate, which either reverts to the starting material, or proceeds to the transesterified product (RCOOR). The various species exist in equilibrium, and the product distribution depends on the relative energies of the reactant and product.