Disobeying a local authority’s rules can be a sin, but it would not be a mortal sin, since it is not grave matter.
You simply violated a (very) local ordinance about not conducting monetary transactions on school premises. I seriously doubt it qualifies as sinful anyway - it’s not like you’re using the school to carry on a business, but just making a private agreement between two individuals.
I imagine the school rule is there to stop people making lots of stuff and using the school community to make a profit, because you’re at school to learn and not to spend your time thinking about selling to your schoolmates. If you were to do it, you’d have to do it not on school time.
Summary: I don’t think you sinned at all, but if you did it would never be anything other than a minor sin and nothing that needs to be confessed.
It’s entirely up to you if you want to get your $2 at school. If you don’t, then simply wait until end of classes, step outside the boundary of the school and exchange the money on the sidewalk. That way you’re in the clear.