Usul al-Kafi
Book 4:
The Book of Divine Proof

Chapter75
Imamate of Imam al-Hasan al-Askari (p): the eleventh Imam

437. 1. Yahya Ibn Yasar al-Qanbari: Imam Ali an-Naqi (p) appointed his son Imam al-Hasan al-Askari (p) as his successor four months before he passed away and he made me and a group of independent men as witnesses.

438. 3. Abdullah Ibn Muhammad al-Isfahani reports that Imam Ali an-Naqi (p) said: Your master after me is the one who will recite the prayer (for the dead) over me.
The narrator said that they did not know of (the existence of) Imam al-Hasan al-Askari (p) before this incident. He said, then (after the death of Imam Ali an-Naqi (p)) Imam al-Hasan al-Askari (p) appeared and recited the funeral prayer over him.