I deployed governor contract on Amoy testnet.
Then I am going to call castVote function in governor but although an address has balance in my erc20 token, the voting power was zero.
I checked the token address, timepoint and set the ERC20Votes.
But I can't find reason.
Plz help me if you have experience.
Kind regards,
Peter
Hi Peter,
So I (and others) can better understand could you please post the code for both contracts? FYI - using ``` before and after the code (this helps convert the code to a readable format).
Is your issue:
- you have deployed a contract on a testnet (presumably importing a custom token);
- you've loaded an address with these tokens; and
- you call
castVote
, however this does not appear to represent a vote cast in the context of the contract?
Let me know if I've misunderstood.
Thank you for your response.
Here is detailed code.
Token contract
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol";
contract MyToken is ERC20, ERC20Votes {
address public admin;
address public minter;
// Address of token holders
address[] public tokenHolders;
constructor()
ERC20("MyToken", "MT")
ERC20Permit("MyToken")
{
admin = msg.sender;
// _mint(msg.sender, dailyProduction * 360 * 1e19);
}
Governor contract
import "@openzeppelin/contracts/governance/Governor.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorSettings.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorCountingSimple.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorVotes.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorVotesQuorumFraction.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorTimelockControl.sol";
contract GFEGovernor is
Governor,
GovernorSettings,
GovernorCountingSimple,
GovernorVotes,
GovernorVotesQuorumFraction,
GovernorTimelockControl
{
// /* 1 day */ /* 1 week */
constructor(
IVotes _token,
TimelockController _timelock
)
Governor("MyTokenGovernor")
GovernorSettings(7200, 50400, 0)
GovernorVotes(_token)
GovernorVotesQuorumFraction(4)
GovernorTimelockControl(_timelock)
{}
}
I got the voting power of specific address which hold token balance but the voting power was zero.
Here is code for that.
const currentHeight = await getCurrentBlockHeight();
console.log("current height: ", currentHeight);
// get votes
const accountPower = await GovernorContract.methods.getPastVotes(user2Account.address, currentHeight).call();
console.log("account power: ", accountPower);
I found issue.
To get voting power, users should call delegate function before start voting.
1 Like
Awesome to hear you solved it, I'm sorry I couldn't come back sooner to assist!