The most important law in this regard would be § 1973i(c) of the US criminal code which reads:
Whoever knowingly or willfully [...] pays or offers to pay or
accepts payment either for registration to vote
or for voting shall be fined not more than $10,000
or imprisoned not more than five years, or both. [...]
This law only applies to payments made explicitly in exchange for voting. Supporting private charities from their own pockets or through public endorsements is very common for politicians, especially during campaign season. It is hard to deny that a politician will at least partially be motivated to do this in order to improve their general popularity and thus their election result. But in order to call this election fraud, they would have to explicitly state that they expect that a specific person will vote in exchange for a monetary donation.
For example, this would be allowed:
I donated $10,000 to this library because this government doesn't do enough to support public education. If you think libraries need more public funding, vote for me!
This would be illegal:
I donated $10,000 to this library. Now I expect everyone who works here to vote for me next election, or I want my money back.
Note that additional state level laws might apply.