In short, according to Spanish law:

you can’t sell or buy marijuana, hashish, etc…;
possession of marijuana is prohibited;
you cannot consume marijuana in public places.

This is the most important thing you need to know, but at the same time:

you can grow 2 plants and take the cannabis inside your private space in such a way that nobody else can see it;
you can become a member of a cannabis club (not exactly the same as a coffee shop) and consume marijuana inside its walls.

Cannabis clubs or as they are commonly called in Spain, – Cannabis Associations or Cannabis Social Clubs, are non-profit, socialization and leisure organizations, where with the funds from the membership fees marijuana is grown to be shared and consumed strictly within the circle of members.

Only members have access to the club: these are private organizations closed to outsiders and membership is by invitation only from an existing member of the association. That means that you cannot simply walk in off the street without an invitation, you will be refused access. That is what the important distinction between cannabis associations and public coffeeshops in Amsterdam is mainly about.

It sounds complicated, but in reality everything is simpler than it seems. Formalities in the form of an invitation and membership in a club are necessary to comply with the letter of the law. In clubs, there is no concept of sale or purchase, only voluntary dues. It is inappropriate to use the word “buy” here, instead we say “get”, “have” or “try”. 

You don’t have to worry about the security and privacy of your personal data. All cannabis clubs take this issue with great responsibility and allocate a large part of their budget to the protection and storage of personal data. Under no circumstances does the club share its members’ data with third parties.

It is possible that in Barcelona you will be invited to a “coffee shop” or a “cannabis club” on the street. Be aware that such invitations are illegal: associations do not have the right to advertise on the street and they use the services of promoters. Stay away from street vendors. Especially in the center, you will come across many offers to buy weed, hashish and the like. But because of the legal alternative in the form of cannabis associations, there are some very fringe elements that do as well. Their target audience is tourists who are not oriented in the local cannabis situation. There are many cases of travelers who have been robbed under this pretext.

Black market offers can be divided into two types: buying marijuana directly from the hands on the street or going to a fake “smoking club”, usually a dark basement. These places, of course, have nothing to do with real clubs. It’s just speculation that many tourists have heard about, but have no idea what they should be like. In both cases, you acquire a junk-quality marijuana and potential problems with the police await you, because by acting this way you become a participant in the drug trade.