Idris Haroon Degmaster, of Plover Street, Preston, was caught in possession of 0.3 grams of the class A drug in the city on July 28 last year, Preston Crown Court was told.
He initially pleaded not guilty to a charge of possession with intent to supply, but then changed his plea to guilty at a hearing in August.
Judge Beverly Lunt sentenced the 27-year-old defendant to two and a half years in prison.
She ordered a quantity of money which was discovered on him to be seized and forfeited by the court, and made an order for the drugs to be seized and destroyed.
When an offender is convicted of an offence under the Misuse of Drugs Act 1971, the judge can order forfeiture and destruction of anything shown to the satisfaction of the court to relate to the offence.