https://en.wikipedia.org/wiki/History_of_money
Bartering was never the primary source of trade, and in prehistory, gift economies and sometimes loose concepts of debt occurred, while bartering was limited to potentially just strangers and enemies. The prehistory section is quite interesting here.
It seems that after prehistory during the formation of agriculture, instead of going to a barter based economy, "ledgers" were kept instead, which introduced the concept of debt and credit.
Note: I am not an anthropologist.