0

I have a few questions regarding ETH and token storage.

  1. Is it a good practice to store ETH on smart contract address in case only owner is authorized to withdraw it?

  2. When deploing smart contract, do I have to send all available tokens to some external wallet address in my constructor function? Or I can leave tokens on smart contract address and send them to clients from contract address during crowdsale?

  3. Summerizing the above two questions, how to distinguish balances of ETH and tokens on smart contract address? I mean does: address(this).balance returns ETH quantity and balances[address(this)] returns token quantity? Or they are similar?

1

There is nothing magical about tokens - they behave exactly as you write them to behave. So you can write them in whatever way you wish.

If you mean ERC20 compliant tokens, the situation is only a little bit different. The ERC20 standard tell you what functions you have to have in the token contract but you can implement them as you wish.

The balance part in address(this).balance is an Ethereum internal variable which stores the address's balance. The balances in balances[address(this)] is something you have written inside the token contract and the ERC20 standard doesn't actually state anything about such a variable. The variable could be called for example thoseBalances in the token contract and it would still be ERC20 compatible.

As for your first actual question: storing ETH in a contract is not much different from storing it in a wallet if the contract is properly written. Wallets are typically a safer choice security-wise but it's often more convenient to have the Ether in the contract so the contract can use it directly.

As for your second question: it's up to you, you don't have to do anything. Tokens are just code inside a token contract which is probably written by you.

  • Thanks for reply. Still one of issues is not pretty clear form me. For example if i use contract address to store both ETH and tokens of this contract, which functions I must use to get balance of ETH and balance of tokens? – Сергей Гринев Oct 2 '18 at 12:09
  • If it's an ERC20 token, it has a balanceOf function, so you should use that. And for ETH balance, use the balance variable. Here's the ERC20 specification: theethereum.wiki/w/index.php/ERC20_Token_Standard – Lauri Peltonen Oct 2 '18 at 12:11

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.