You're right that the energy cost is incurred at the block-level, but since each block can hold a certain number of transactions, you can then infer what the effective cost is per transaction. The source for kWh per transaction comes from Digiconomist's bitcoin energy consumption index, and you can find their methodology here: https://digiconomist.net/bitcoin-energy-consumption#assumpti...