A telecoms worker set up a cannabis "grow house" in his home after he began using the drug for pain relief from a back injury, a court heard.
Teige O Loideoin (32) had eight plants growing in a cultivation tent and €4,000 worth of the drug in a drawer when gardai raided his apartment.
He grew it himself because he did not want to "deal with other people" by buying it.
Judge David Waters adjourned the case for the production of a pre-sentence probation report.
Father-of-one O Loideoin, of Lock House, Goldenbridge Terrace, Inchicore, Dublin 8, pleaded guilty to cultivation and sale or supply of cannabis at that address last May 7.
The court heard gardai searched the apartment at around 10pm on the date in question. During the search, eight cannabis plants of mid-maturity were found growing under lights and fans.
The plants would have been worth a potential €800 each when mature. In a drawer in the living room, €4,000 worth of cannabis herb was found along with weighing scales and bags.
The accused was arrested and taken to Kevin Street Garda Station, where he co-operated.
He said he sold some cannabis to his close friends. He had no previous convictions.
The court heard O Loideoin was embarrassed by the offences and remorseful. He suffered a fracture to his vertebrae in an accident in 2010 and the medication he was prescribed had an adverse side-effect.
"He made an error, a foolish mistake of going down this route to self-medicate," his lawyer said.
The judge asked: "So it was all produced in the grow house he had in his apartment?"
O Loideoin worked in tech support in a large telecoms company.
"My principal concern here is the quantity," the judge said.
"It seems to be in excess of what would be required to self-medicate and provide a small amount to friends."