Electrocatalytic N 2 fixation represents an energy-efficient and long-term sustainable approach, which can convert N 2 to NO 3 – or NH 3 via the electrochemical N 2 oxidation reaction (NOR) or N 2 reduction reaction (NRR). However, the inert N 2 molecule, low activity of electrocatalysts, and predisposed competitive reactions result in the poor yields and Faradaic efficiencies of N 2 fixation reactions, which greatly restrict the application of such green synthesis technology. In this work, a molecular-level post-modification strategy has been explored to integrate diverse alkyl chains on a ferriporphyrin-based metal–organic framework (MOF) PCN-222(Fe), which provides adjustable hydrophobicity and highly dispersed active sites. The increased lengths of alkyl groups can gradually improve the hydrophobicity of decorated MOFs, which effectively suppress the competitive reactions and boost the electrocatalytic NOR and NRR performances. Significantly, the highest Faradaic efficiency of 70.7% so far and a state-of-the-art NO 3 − yield of 110.9 μg h –1 mg cat. –1 can be achieved for NOR, which are attributed to the synergistic effect of FeN 4 active sites, high porosity, and strong hydrophobicity for n -octadecylphosphonic acid (OPA) decorated PCN-222(Fe). The hydrophobicity of ferriporphyrin-based MOF can be modulated using the molecular-level post-modification strategy, which remarkably boosts the electrocatalytic performances for N 2 oxidation to NO 3 – or N 2 reduction to NH 3 under ambient conditions. The highest Faradaic efficiency of 70.7% by far and a state-of-the-art of NO 3 − yield of 110.9 μg h –1 mg cat. –1 are realized for nitrogen oxidation reaction, in virtue of the synergistic effect of ferriporphyrin active sites, high porosity, and enhanced hydrophobicity. • The hydrophobicity of a ferriporphyrin-based MOF can be well modulated by the molecular-level post-modification strategy. • The enhanced hydrophobicity remarkably boosts the electrocatalytic performances for ambient N 2 oxidation or N 2 reduction reaction. • The Faradaic efficiency of 70.7% and a NO 3 − yield of 110.9 μg h –1 mg cat. –1 are realized for nitrogen oxidation reaction.