A nitrogen-thermal approach via the reaction between transition metal species and N dopants affords us the ability to optimize the tradeoff between the number of exposed transition metal/carbon (exemplified by cobalt in this work) boundaries and the most pronounced interfacial rectifying contact to achieve the highly efficient and selective hydrogenation and dehydrogenation of N-heterocycle compounds in a reversible manner.