4. For the positive integer $n$, define $a_{n}$ as the unit digit of $n^{(n+1)^{n+2}}$. Then $\sum_{n=1}^{2010} a_{n}=$ $\qquad$ .
4.5 829 .

When $n \equiv 0,1,5,6(\bmod 10)$, $a_{n} \equiv n^{(n+1)^{n+2}} \equiv n(\bmod 10)$;
When $n \equiv 2,4,8(\bmod 10)$,
$$
\begin{array}{l}
(n+1)^{n+2} \equiv 1(\bmod 4) \\
\Rightarrow a_{n} \equiv n^{(n+1)^{n+2}}=n^{4 k+1} \equiv n(\bmod 10) ;
\end{array}
$$

When $n \equiv 3,7,9(\bmod 10)$,
$$
\begin{array}{l}
(n+1)^{n+2} \equiv 0(\bmod 4) \\
\Rightarrow a_{n} \equiv n^{(n+1)^{n+2}}=n^{4 k} \equiv 1(\bmod 10) .
\end{array}
$$

Therefore, $a_{n}$ is sequentially $1,2,1,4,5,6,1,8,1,0,1$, $2, \cdots$ which is a periodic sequence, with the smallest positive period being 10.
Thus, $\sum_{n=1}^{2010} a_{n}=201 \times 29=5829$.