If you sell something for actual money, and use that actual money to buy something else, that sale would usually be a taxable event (well, it would be a realization event which may or may not be a taxable event, but in casual conversation just saying "taxable event" is fine).
If actual money is not involved, for example I trade my X with you for your Y, then it gets quite interesting. In the US there are generally two ways that tax law handles this. I don't know how far along the law is with fitting all the various cryptocurrency things into this.
One way is to treat it for tax purposes as if I sold X at its fair market value and you sold Y at its fair market value, and then I bought Y and you bought X. I'm taxes on my gains from that imputed sale, and take that price as my basis in Y. Similar for you.
The other way to treat it is as a non-realization event, putting off any tax consequences until I actually sell Y or trade it for something that gets handled as an imputed sale. My basis in Y is the same as the basis I had in X.
What determines which of these applies is whether or not the exchange is a "like-kind exchange". If the exchange is a like-kind exchange it gets the "swap basis" approach. If it is not like-kind it gets the "imputed sale" approach.
Sometimes this is clear cut. Suppose I bought an old guitar at garage sale 50 years ago for a couple dollars that is nowadays a valuable vintage guitar worth $100k, and 50 years ago you bought a new comic book that is now worth $100k to collectors.
If we trade, that would be an imputed sale because guitars and comic books are not like-kind.
When things are in the same category it gets much harder, and the case law is full of courts having to go deeply into philosophical questions of what makes things like-kind.
Say we trade paintings. Are all paintings like-kind? Or would a Monet not be like-kind with a Picasso because they are different artists and/or different styles? Is a male horse like kind with a female horse? Is an electric guitar like kind with an acoustic guitar? Is a comic book that is valuable because of the first appearance of a character like-kind with a comic book that is valuable because of who inked it?