Drug dealer Nathan Cayton, of Castleland Street, Barry pleaded guilty at Cardiff Crown Court after he was caught with 31 MDMA tablets.
The offence relates to an incident in Cardiff on June 20, 2025.
Cayton also admitted possessing 0.58g of cocaine on the same date.
The Recorder of Cardiff, Judge Tracey Lloyd-Clarke ordered the preparation of a pre-sentence.
He was granted unconditional bail and will return to the crown court on September 30 for sentencing.
Alice Sykes represented Cayton, while Marian Lewis appeared for the prosecution.
