Ryan Warner, aged 19, raised officers' suspicions when he was spotted in Castle Walk park in Shrewsbury in a thick winter coat on a hot summer's day on July 26 last year.
He was with another man, who fled the scene. Warner tried to escape officers but was stopped by the riverside.
Philip Beardwell, prosecuting at Shrewsbury Crown Court, described Castle Walk park as having "developed a reputation" for being an area in the town where drug dealing takes place.
He said when officers stopped Warner, they asked if he was carrying any weapons that could hurt them. Warner surrendered the Stanley knife, and was searched. Officers found 4.39g of heroin in Warner's possession, broken down into street deals. He was arrested and gave a no comment interview to police.
Warner, of Parkfield Road, Dudley, West Midlands, pleaded guilty to possession with intent to supply a Class A drug and possession of a blade in a public place.
Tarlowchan Dubb, mitigating, accepted Warner's offending passed the custody threshold, but asked District Judge Peter John Veits to take into consideration his youth, the delay in proceedings getting to court and his lack of any previous convictions.
"He was vulnerable to exploitation by more sophisticated criminals," said Mr Dubb, who also told the court Warner had a heroin addiction. "They took advantage of his naivety."
Judge Veits told Warner: "You got yourself involved in drug dealing. As many people do, you started with a habit and then got into debt.
"It's clear that you were drug dealing in Shrewsbury. You had 72 wraps of heroin - a significant amount.
"You also had a knife with you, making matters worse. When people carry knives, it can end up with people being seriously injured or dead."
However the judge said he felt sending Warner to prison would only turn him into a "hardened criminal".
Warner was given an 18-month sentence in a young offenders' institute, suspended for two years. He must also carry out 100 hours of unpaid work and do 40 rehabilitation activity days.
District Judge Veits also ordered forfeiture and destruction of the drugs and the knife which were seized by police.
"This is a chance to turn your life around," the judge told Warner. "I hope you can take advantage."