We prove a trace formula in stable motivic homotopy theory for an endomorphism of a smooth and proper scheme over a general base scheme. When the base is a field, we compute the local terms explicitly by showing that the Euler characteristic of an etale algebra is the class of its trace form in the Grothendieck--Witt ring. |