i created an erc20 token and i'm trying to create a smart contract that stores some informations in a blockchain just if the wallet contain my tokens.

How can i do this? Have i to work on the token creation contract or on the other smart contract that stores information?

closed as unclear what you're asking by Rosco Kalis, Achala Dissanayake, shane, flygoing, Briomkez Jan 21 at 16:47

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


The ERC20 standard exposes a balanceOf function which will return the token balance of a given address.

In your smart contract (contract 2) you can check the balance of that address within the context of the token contract (contract 1) you created.

pragma solidity ^0.4.17;

contract ERC20 {
    function totalSupply() public constant returns (uint);
    function balanceOf(address tokenOwner) public constant returns (uint balance);
    function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
    function transfer(address to, uint tokens) public returns (bool success);
    function approve(address spender, uint tokens) public returns (bool success);
    function transferFrom(address from, address to, uint tokens) public returns (bool success);
    event Transfer(address indexed from, address indexed to, uint tokens);
    event Approval(address indexed tokenOwner, address indexed spender, uint tokens);

contract MyContract {
  address token_address = // Address here;

  function hasTokens() public returns (bool) {
    let balance = ERC20(token_address).balanceOf(msg.sender);
    return (balance > 0);


From there, you can call the hasTokens() function whenever you want to check within your smart contract that a user has some token balance in token_address contract.

  • Thank you, so i haven't to put this function in the ERC20 contract that is used to create the token but in the other contracts that i want to deploy, true? – Simone R.C. Jan 21 at 14:44
  • Yeah, your ERC20 token will already expose balanceOf so you will have everything you need. – Shawn Tabrizi Jan 21 at 15:00

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