A hypoelliptic operator in the Heisenberg calculus on a compact contact manifold is a Fredholm operator. Its symbol determines an element in the K-theory of the noncommutative algebra of Heisenberg symbols. We construct a periodic cyclic cocycle which, when paired with the Connes-Chern character of the principal Heisenberg symbol, calculates the index. Our index formula is local, i.e. given as a local expression in terms of the principal symbol of the operator and a connection on TM and its curvature. We prove our index formula by reduction to Boutet de Monvel's index theorem for Toeplitz operators.