A man walked into a bar in Derry with a bag containing class A drugs worth almost £40,000, a court has heard.