2

I'm looking to run a private Ethereum blockchain. But I wanted to check first, is it possible for an account to hold multiple custom tokens?

For example, can an account hold tokens that denote very simple points(e.g. 100 tokens = 100 points), and another token that is unique (e.g. collectable once only). This is an example with 2 kinds of tokens, but there could be more.

1

Yes. You can run multiple custom tokens on a private Ethereum blockchain.

There is a token standard ERC: Token standard #20 that standardises the methods and events for a token smart contract on the Ethereum blockchain. You can find a list of ERC20 compliant token contacts on the Ethereum mainnet blockchain at https://etherscan.io/token-search.

Each ERC20 compliant token contract should have a data structure like the following to store the user's account and token balance:

mapping (address => uint256) balances;

Each ERC20 compliant token contract will have the following methods to:

  • Query the token balance belonging to an address

    function balanceOf(address _owner) constant returns (uint256 balance)
    
  • Transfer the token balance from one address to another address

    function transfer(address _to, uint256 _value) returns (bool success)
    

Here's a simplified token contract based on The DAO's (with the USD 50 million bug) source code:

contract TokenA {
    mapping (address => uint256) balances;

    event Transfer(address indexed _from, address indexed _to, uint256 _amount);

    function balanceOf(address _owner) constant returns (uint256 balance) {
        return balances[_owner];
    }

    function transfer(address _to, uint256 _amount) noEther returns (bool success) {
        if (balances[msg.sender] >= _amount && _amount > 0) {
            balances[msg.sender] -= _amount;
            balances[_to] += _amount;
            Transfer(msg.sender, _to, _amount);
            return true;
        } else {
           return false;
        }
    }
}

As you will see in the contract code, your address will just be a entry in the smart contract mapping table. You can have multiple token contracts, each with their own mapping tables. You can have the same address existing in the mapping tables in one or more of these token contracts.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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