I am planning to build a smart contract and I have a general question about smart contracts before starting to program:

  1. is it possible to build a smart contract that holds ERC-20 tokens where ownership of these tokens is linked to the address that deposited these tokens? I think this one should be possible and quite "easy" to programm

  2. can I program my smart contract so that the owner of this token can use the (vested) token to participate in certain votings or does this always depend on how the other smart contract which would have to be called for voting is programmed? I somehow doubt this is possible

I just imagine how people can use their tokens which are stored in a contract for certain tasks.

Thanks in advance!

1 Answer 1


Yes, both are possible.

You would "have" two contracts:

  1. The token contract which holds the balance each token holder has. Calling balanceOf(address) of the token contract and passing an address will return the amount of tokens that accounts of said token.
  2. Your contract, which would instantiate the ERC20 token to do something based on the balanceOf that token for the user executing your contract.

Since balanceOf is public and you can easily instantiate an ERC20 token if you know its address, you can basically check any user's balance of any given token.

Just instantiate the ERC20 token from your contract and do balanceOf(msg.sender) to get the balance, then you can use that number to vote. (either a one-person, one-vote or a weighted voting based on each user's balance).

For the second question, technically, you wouldn't have to do any additional steps. At least, based on vesting contracts I've seen, the tokens are not added to the user balance until they "withdraw" them from the vesting contract. So, if my tokens were under some kind of vesting, calling balanceOf would only return the tokens I already withdrawn.

  • ok I just want to be sure that the question was understood correctly. regarding the voting I assume the following conditions: 1. ERC-20 token is vested / safed within MY smart contract and linked to a user address (that deposited this token before) 2. the user wants to instantiate the vote and therefore calls MY smart contract that holds his ERC-20 token 3. the user calls the ERC20 token contract that provides a function that checks the users token-balance for voting Can this - somehow - be implemented?
    – marc0olo
    Commented Dec 5, 2017 at 0:41
  • what I mean is -> the user wants to vote on the ERC-20 token contract and this contract somehow needs to get his token balance from my smart contract. sounds a bit crazy while writing that down :D
    – marc0olo
    Commented Dec 5, 2017 at 0:49
  • I mean a voting mechanism like Modum modum.io/milestone-1 used. Here a function of the modum smart contract has to be called and this checks the token balance of the user. But since the user would have locked up the tokens in my smart contract I want him to be able to confirm his balance via my smart contract. In this case the modum smart contract function would need to communicate with a function in my smart contract, right? Or is there another possibility to achieve that? Or am I just misunderstanding something?
    – marc0olo
    Commented Dec 5, 2017 at 1:59
  • I'd keep the logic separated. There's the token contract which all it does is hold each user's balance (like almost every single ERC20 token does). Whichever other contract that wants to implement voting based on users' balance of said token, would try to get his balance from the token contract and use that value to perform the logic in this other contract. Create your token contract, have people hold some balance in it buy buying the tokens, and then other contracts could reference your token contract to perfom some logic based on their balance in your contract, like casting a vote. Commented Dec 5, 2017 at 4:06
  • yeah ok so in my example modum contract would have to reference my contract somehow in order to get the token-balance of a specific user and modum contract would have to trust my contract that my contract returns the correct balance, correct?
    – marc0olo
    Commented Dec 5, 2017 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.