A 19-year-old man sold cannabis to a 15-year-old boy because he was fearful of suffering violence from his dealer.
Marley Hollins began to sell cannabis because he was in debt to the dealer, Skipton magistrates were told.
Hollins pleaded guilty to supplying a class B controlled drug to a schoolboy - magistrates ordered the youth's name should not be published - and to possessing cannabis with intent to supply on January 17.
Hollins of Brougham Street, Skipton, was told that he could face imprisonment but, because it was his first offence, the bench was being more lenient.
He was sentenced to a two-year community order with supervision and 200 hours unpaid work. He was also ordered to pay £85 court costs and a £60 victims surcharge.
Katy Varlow, prosecuting, said Hollins was arrested by police after they had spoken to the 15-year-old.
He was very frank with detectives, telling them he had been selling cannabis to friends for about three months and he did not realise the boy was only 15.
He said he had begun selling cannabis to settle a drugs debt with his dealer.
John Mewies, for Hollins, said the drug sales were on a low scale.
Since his arrest he had voluntarily been attending a drugs rehabilitation programme in Skipton.