The usual way to go about it is you commission the cover art from an artist, they give you their rates, final payment is sent, you get the image and so on. It will be difficult to find someone to do the work for free or do the work first then promise payment once the book starts making money, it's a risk.
Oh I know that, I just meant what if the book sold like 100 000 copies (I know it wont haha), that's $100 000 and the artist got their commission rate? Also isn't there legal rights and royalties and such, or does that change with regards to cover art?
It depends largely on the agreement between the client and the artist, if they choose to have royalties involved then so be it but that's kind of an odd thing to happen with book covers, usually you just pay for the completed cover art and that's that you will rarely if ever get talks about royalties.