Preston Crown Court heard Paul Evans, 43, of Hawthorn Street, Audenshaw, Manchester, had agreed to deal the drugs in Lancaster to pay off a drug debt.
Prosecuting, Clare Thomas said an officer on patrol in Morecambe in December 2018 had pulled over a Ford Focus he was driving due to concern about his driving.
She added: " He could smell cannabis coming from the vehicle and arrested him on suspicion of drug driving. He then searched the defendant and found him to be in possession of £210.16 cash and 35 individual wrapped brown and white packages in clear packaging.
"A mobile phone was found in the car.
"The defendant said he was staying at a Travelodge in Morecambe and had a door key in his possession.
"A further mobile phone was found in the room."
An examination recovered text messages showing he was dealing on the street.
In all, officers seized 4.5g of heroin, 0.89g crack cocaine and two other packages of heroin, with a street value of £380.
In a police interview Evans admitted he had collected drugs from Manchester and drove to Morecambe intending to sell three wraps for £20 to "get money to get himself back on his feet".
The court heard he had previous convictions but no recent ones,
Defending, Anthony Parkinson said: "He made full and frank admissions in his interview.
"He says when he was sentenced to Manchester to deal drugs he did so because he built up a debt.
" It is, I'm afraid, the usual sorry story that he built up a debt that was not affordable, and the easy way out for him was to supply drugs under the direction of other people."
Judge Heather Lloyd remarked his candour had been tarnished by his attempts in his pre sentence report to distance himself from the offences.
She said: " You told the author of the pre sentence report that what you were doing was not proper drug dealing.
"Yes, it was.
"You tried to distance yourself from the offending.
"I'm now told you were doing it to enable you to pay off a debt.
"You were prepared to go out and cause misery to others."
The Lancashire Post is more reliant than ever on you taking out a digital subscription to support our journalism. For unlimited access to Lancashire news and information online, you can subscribe here.