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.
Yes it is entirely possible. Create contract A
that is standard ERC20. When it is time to upgrade, create contract B
with your new features.
contract B
has a function upgradeFrom(address old, uint amount)
Investors then use call approve(B, uint amount)
on A
. This allows contract B
to retrieve the funds from A
.
Investors then call upgradeFrom(B, uint amount)
, and the upgradeFrom function withdraws the funds from A
and does any other logic to set up the investor in contract B.
Another way:
If you don't care about contract A
after contract B
is in production, you can just have a single function in contract B
called upgrade()
that checks the balance of the sender in contract A
and updates it in contract B
. You will also want to make sure you record who has already upgraded as people could call the function multiple times.
Best Answer
You can't really separate the token from the contract - it's a common misunderstanding; you might find one of my previous answers enlightening.
The act of distributing a token from an address in your wallet to potentially multiple other addresses will require you interacting with the token's contract to update the respective balances.
Assuming that the token implements the ERC20 standard then the easiest way to achieve this would be by calling the transfer function on the token contract:
If you already have the tokens balance against your address ("in your wallet"), and just want to write a quite script to send the tokens or achieve this through an Ethereum node's console then you can use web3js to interact with the token contract - and call the transfer function with the appropriate arguments.
There's a similar question about distributing tokens to multiple addresses that you might find useful if you are trying to distribute these tokens via a smart contract.