Bayes estimate of beta distribution I'm trying to derive Bayes estimate of a beta distribution.

We toss n coins i.i.d., and get X heads. Give the prior distribution for $\theta$ of the coin is beta(a,b), Bayes estimate maximize the poster distribution, which is also a beta distribution beta(a+X, b+n-X)

Basically we're maximizing:

$\int_0^1 \theta^{a+X-1}(1-\theta)^{b+n-X-1}\theta d\theta$

And the result is: $\theta=\frac{a+X}{b+n-X}$. How to derive this from the integral?
As you said, the posterior distribution is the beta distribution $(a+X, b+n-X)$. The mean of the beta distribution $(\alpha,\beta)$ is $\alpha/(\alpha+\beta)$ hence the posterior mean is $\hat\theta=(a+X)/(a+b+n)$.

Note that $0\leqslant X\leqslant n$ with full probability hence $0\lt\hat\theta\lt1$ with full probability. (By contrast the suggestion $\hat\theta=(a+X)/(b+n-X)$ in your post is absurd since if $X$ is large, $\hat\theta$ can be as large as $(a+n)/b$, which can be larger than $1$.)
The bayes estimate is simply the mean of beta distribution $E[\theta]$, which should be $\theta=\frac{a+X}{b+n-X}$.