Proving that $\operatorname{trace}(T) =\langle Te_1,e_1\rangle +\cdots+\langle Te_n,e_n\rangle $?
Solution 1:
Since we have an orthonormal basis, we (ought to) know that
$$\forall\,x\in V\;,\;\;x=\sum_{k=1}^n\langle x,e_k\rangle e_k$$
Using the above and since the trace is an invariant of an operator, let us check what the matrix representation of $\;T\;$ wrt the basis $\;\{e_1,...,e_n\}\;$ is:
$$Te_i=\sum_{k_1}^n\langle Te_i,e_k\rangle e_k$$
and from here we get at once what we want.
Solution 2:
Because for an othogonal basis $B=(e_1,\ldots,e_n)$, the coordinate function for $e_i$ is $x\mapsto\langle x,e_i\rangle$. (You can see by taking for $x$ any linear combination of $e_1,\ldots,e_n$, and checking that this extracts the coefficient of $e_i$.) Then $\langle Te_i,e_i\rangle$ is the $i$-th coordinate of the vector $Te_i$ when expressed in the basis$~B$. The list of all such coordinates of $Te_i$ form column$~i$ of the matrix for $T$ in the basis$~B$, so this is taking the $i$-th diagonal entry, and summing just gives the trace of that matrix.