Trace map for finitely generated projective modules Let $R$ be a commutative ring with unity. We can define the Trace map $\text{Tr}\colon\text{Hom}_R(R^n,R^n)\rightarrow R$ for a free finite module in this way: fixed a basis $(e_1,\dots,e_n)$, we have $f(e_k)=\sum_{h=1}^na_{hk}e_h$ for $f\in\text{Hom}_R(R^n,R^n)$, therefore, as for finite dimensional vector spaces, $\text{Tr}(f)=\sum_{h=1}^na_{hh}$. Moreover this satisfies $\text{Tr}(f\circ g)=\text{Tr}(g\circ f)$. From this we can deduce Trace is well defined.
We can extend this definition to finitely generated projective modules. Let $P$ such a module generated by $\{p_1\dots,p_n\}$. Then there exist a projection $\pi\colon R^n\rightarrow P$ from a finite free module and a section $i\colon P\rightarrow R^n$ such that $\pi\circ i=1$. For $f\in\text{Hom}_R(P,P)$ we define $\text{Tr}_P(f)\colon=\text{Tr}(i\circ f\circ\pi)$.
I want to prove that this definition is independent of choices.
This was my attempt. I fixed a basis $(x_1,\dots,x_n)$ for $R^n$ such that $\pi(x_k)=p_k,\ i(p_k)=x_k$, then I took another projection $q\colon R^m\rightarrow P$ from a finite free module (with $m\geq n$) and another section $j\colon P\rightarrow R^m$ such that $q\circ j=1$. If $(y_1\dots,y_m)$ is a basis for $R^m$ such that $q(y_k)=p_k$ for $k=1,\dots,n$ and $q(y_k)=0$ otherwise; and $j(p_k)=y_k$ , then we have write respectively $i\circ f\circ\pi(x_k)=\sum_{h=1}^na_{hk}x_h$ and $j\circ f\circ q(y_k)=\sum_{h=1}^na_{hk}y_h$ (for $k=1,\dots,n$) while $j\circ f\circ q(y_k)=0$ (for $k=n+1\dots,m$) if $f(p_k)=\sum_{h=1}^na_{hk}p_h$. From this it follows the trace coincides.
However I don't think it sufficies to prove $\text{Tr}_P$ is well defined.
Any help is very appreciated, thanks.
 A: Let $P$ be a projective $R$-module. A dual basis of $P$ is the datum of a tuple of generators $(x_1,\ldots,x_n)$ of $P$ along with a tuple of functionals $(x_1^*,\ldots,x_n^*)$, i.e. $R$-linear maps $P\to R$, such that for every $p\in P$ we have that $p = \sum_{j=1}^n x_j^*(p)x_j$.
Notice that $x = [x_1,\ldots,x_n]^t$ gives us the projection $R^n\to P$ and that $x^* = [x_1^*,\ldots,x_n^*] : P\to R^n$ amounts to a desired section of $P$. In fact, such a finite dual basis exists if and only if $P$ is finitely generated projective. For such a dual basis and $f:P\to P$, write $f_j = x_j^*\circ f$.

Lemma. Let $X=(x,x^*)$ be a dual basis for $P$. Then the map $Y : P\otimes_R P^* \longmapsto \hom_R(P,P)$ such that $Y(x\otimes \psi)(p)= x \psi(p)$ admits an inverse given by $X(f) = \sum_{j=1}^n x_j\otimes f_j$.

Proof. One computes that $Y(X(f))(p) = \sum_j x_j f_j(p) = \sum_j x_j x_j^\ast(f(p)) = f(p)$.
Similarly, if $x,p\in P$ and $\varphi\in P^*$ one computes that $Y(x\otimes \varphi)_j= x_j^*(x)\varphi$, as $x_j^*$ is $R$-linear and $\varphi$ is a scalar, so that $$X(Y(x\otimes\varphi))= \sum_j x_j\otimes x^*_j(x)\varphi = \sum_j x_jx^*_j(x)\otimes \varphi = x\otimes\varphi.$$

Corollary. If $X$ and $X'$ are dual bases of $P$, then they induce the same map $\hom_R(P,P)\to P\otimes_R P^*$.

Proof. Both maps are the unique inverse to $Y$.
Your definition says precisely that if $f\in \hom_R(P,P)$ and if $X= (x,x^*)$ is a dual basis of $P$, then $Tr_X(f) = \sum_j x_j^*(f(x_j))$. That is, if we consider the natural map
$$E: P\otimes_R P^* \longrightarrow R$$
such that $E(x\otimes f) = f(x)$, the trace of $f:P\to P$ is just $E(X(f))$. Since $X(f) = X'(f)$ for any other dual basis $X'$, you know a fortiori that $E(X(f)) = E(X'(f))$.
Disclaimer: I wrote everything pretending $R$ is a commutative  ring. One can be a bit more careful to write things formulas in the general case where $R$ is not commutative.
