Aaron Trappe (21) had been "moving around" heroin to pay his own drug debts when gardai stopped him and searched him.
Trappe, of Santry Lodge, Ballymun, pleaded guilty at Dublin District Court to possession of heroin with intent to sell or supply at McDonald's, Northwood, on October 6, 2011.
The court heard he was stopped and searched at 6.45pm. He had two bags, one of which contained 11 deals of diamorphine and the other an uncut lump of the drug.
The drugs had a street value of €1,194. He told gardai that he had the drug for his own personal use.
He had previous convictions for drugs offences, and had been given a suspended sentence for sale or supply a month after the latest incident.
Trappe had a previous difficulty with drug addiction and had found himself out of the family home and living in hostels, his solicitor said. He developed a serious drug addiction while living on the streets.
Trappe found himself in debt to "a number of individuals" who he had been buying drugs from. He was asked to hold drugs and move them around the place for these people.
On the evening he was told by gardai that he was going to be searched, he handed the drugs he had over. He then made "some admissions".
Trappe was now out of hostel accommodation and living in a "half-way house". He was trying to rehabilitate himself, his solicitor said.
"He was not a man who was stealing to feed his own habit, it is simply that he finds himself in difficulty with possessing the drugs," the defendant's solicitor added.
Judge McNamara suspended the sentence for a year.