Mamun called the young Imam (AS) to Baghdad from Madina and offered his daughter. This infuriated his family (Banu Abbas). To prove to them the excellence of Imam even at a young age he arranged a meeting between Imam and the most learned of men at that time -Yahya bin Athkam. It was a grand occasion with some 900 other scholars present. Imam (AS) wasfirst asked by Yahya:
"What is the compensation (kaffara) for a person in Ehraam who hunted and killed his prey?" Imam replied that there were many more details required before he could answer the question:
1. Did the Muhrim (one in Ehraam) hunt in the haram or outside?
2. Did the Muhrim know Sharia or not?
3. Did he hunt intentionally or not?
4. Did he hunt for the first time or was this one of many times?
5. Was he free or a slave?
6. Was his prey a bird or an animal?
7. Was it big or small?
8. Had he hunted by day or by night?
9. Was he baligh or not?
10.Was he repentant or not?
11.Was his ehraam for Hajj or Umra?
Yahya was stunned. He looked down and started sweating. Mamun asked the young Imam to answer the question, which he did, and then Imam asked Yayha a question which he could not answer. The Banu Abbas admitted defeat and Mamun took the opportunity to offer his daughter in marraige to Imam. Imam (AS) read his own Nika (the khutba of which is used today) with the Mehr of 500 dirhams. Imam wrote a letter to Mamun that he would also give Ummul Fadhl Mehr from the wealth of Aakhira. This was in the form of 10 duas which were for fulfilling any hajaat (desires). These duas are found in Mafatihul Jinaan (pg 447 in most copies). Thus his title Al-Jawad (the generous one).
Imam lived for a year in Baghdad with Ummul Fadhl. She was very disobedient to Imam. When she found out that Imam had another wife (from the progeny of Ammar-e-Yasir) and that there was also children she was jealous and angry realizing that her father's plan had failed. She complained to her father who also realized that his plan, to keep the 12th Imam in his progeny, had failed. He was enraged and in his rage he drank heavily and went to the 9th Imam's house and attacked Imam with a sword. Both Ummul Fadhl and a servant saw the attack and believed Imam was dead. Mamun on waking next morning realized the consequences of his attack and was thinking of arranging the disposal of Imam's body when he saw Imam well without a scratch on him. He was confused and asked Imam who showed him an amulet which is called Hirze Jawad Imam told him it was from his grand mother Bibi Fatima Zahra (AS) and kept the wearer safe from all except the angel death. Mamun asked Imam for it and Imam gave him one.
Now Mamun was scared and tried a new tactic. He tried to deviate Imam by sending him beautiful girls and musicians. When he realised nothing was working he let Imam return to Madina. Imam used this time toprepare the masails of Taqleed and Ijtihaad in preparation for the 12th Imam knowing that both the 10th and the 11th Imam would spend most of their lives in prison. He also prepared the people of Madina teaching true Islam knowing that this would be the last time they would be able to receive guidance directly from an Imam for a long time. Ummul Fadhl continuously complained of Imam her father who sent her letters back. Mamun died in 218 a.h. and was succeeded by his brother Mo'tasam Billah. He openly announced that all Shia were not Muslims. He said it was required for people to kill and prosecute Shia, and to destroy property belonging to Shia. Ummul Fadhl now started complaining to her uncle who was sympathetic to her. Mo'tasam called Imam to Baghdad. He asked Imam to pass judgement of how to punish a thief. Imam said only fingers could be cut as the palms were for Allah (as in Qur'an - it is one of the wajib parts to touch the ground during sajda). As this decision was contrary to the decision of the other 'Ulema' it strengthened the position of the Shia. The other 'Ulema' complained to Mo'tasam.
It is he who prepared and wrote books for the masails of Ijtihaad and Taqleed which were essential to prepare believers for the ghaibat of the 12th Imam.
Once when the young Imam was on his way to Baghdad he came across Mamun's party returning from a hunting trip. All the other children on the street ran but the Imam did not. Mamun asked the young Imam, "Why did you not run away?" Imam said the road was wide enough for all of them and neither had he committed a sin. Mamun then asked him his identity.After finding out, he asked Imam what he (Mamun) had in his hands. Imam replied "Allah has created tiny fish in the river. These fish are hunted by the Hawks of the kings and the descendants of the Prophets reveal the secrets".