  We provide general formulae for the topologically twisted index of a general
three-dimensional ${\cal N}\geq 2$ gauge theory with an M-theory or massive
type IIA dual in the large $N$ limit. The index is defined as the
supersymmetric path integral of the theory on $S^2\times S^1$ in the presence
of background magnetic fluxes for the R- and global symmetries and it is
conjectured to reproduce the entropy of magnetically charged static BPS AdS$_4$
black holes. For a class of theories with an M-theory dual, we show that the
logarithm of the index scales indeed as $N^{3/2}$ (and $N^{5/3}$ in the massive
type IIA case). We find an intriguing relation with the (apparently unrelated)
large $N$ limit of the partition function on $S^3$. We also provide a universal
formula for extracting the index from the large $N$ partition function on $S^3$
and its derivatives and point out its analogy with the attractor mechanism for
AdS black holes.
