A man was found with class A drugs after police raided a flat in Buxton, a court heard.
Officers went to the Fairfield Road flat on January 8 to carry out a search, High Peak Magistrates’ Court heard.
During the search, they found a small bag containing a brown powder, later identified as heroin, inside the trouser pocket of Shaun Johnson, prosecutor Jennifer Fitzgerald said.
Officers also found a quantity of self-sealing bags, a set of scales, a piece of tin foil and a homemade crack pipe as well as numerous phones.
In interview, Johnson said he had been staying at the flat which belonged to a friend, sleeping on the sofa for a few days.
He said he regularly used heroin and spent about £30 a day on the drug.
He admitted that all the items, except for the phones, belonged to him.
The 47-year-old, of no fixed abode, admitted possessing a class A drug.
Kirsten Collings, defending, said: “He accepts the heroin was for personal use.
“He has come to court and entered a guilty plea at the earliest opportunity.
“It won’t come as a surprise to you that he has had problems with drugs for a number of years.
“He has been on a script but has had difficulties because of the breakdown of a very long-term relationship of 22 years.
“He found himself without a partner and without a home and slipped back into old habits and began using heroin again.”
The case was adjourned until Wednesday April 8 for the preparation of a pre-sentence report.