Gregory Crowe (38) has had an addiction to heroin for nearly 15 years, and built up a drug debt after he struggled to cope with the end of a long relationship.
The defendant admitted before Blanchardstown District Court to possession of cocaine as well as having the drug for sale or supply.
Garda Sergeant Maria Callaghan said gardai obtained a search warrant and searched Crowe's home at Woodview Heights in Lucan on May 12 last.
During the course of the search, cocaine with a street value of €2,500 was found.
Defence solicitor Simon Fleming said Crowe has had a heroin problem since 1997, but is currently stabilised on methadone, and is focused on reducing his daily intake.
Mr Fleming said the defendant worked for over a decade but is currently out of work due to a back injury.
The court heard the defendant suffered a number of difficulties around the time of the offence, a 17-year relationship with his partner broke up and he had difficulty coping with this.
Mr Fleming said Crowe was close to his sister's husband but he died around the time of the incident, and he had lost another friend in a fire.
Judge Lindsay sentenced Crowe to nine months in prison but suspended it for 18 months.