  Primordial magnetic field generated in the inflationary era can act as a
viable source for the present day intergalactic magnetic field of sufficient
strength. We present a fundamental origin for such a primordial generation of
the magnetic field, namely through anomaly cancellation of $U(1)$ gauge field
in quantum electrodynamics in the context of hilltop inflation. We have
analysed at length the power spectrum of the magnetic field, thus generated,
which turns out to be helical in nature. We have also found that magnetic power
spectrum has significant scale-dependence giving rise to a non-trivial magnetic
spectral index, a key feature of this model. Interestingly, there exists a
large parameter space, where magnetic field of significant strength can be
produced.
