2

I want to better understand how to check how much of a token is in my account and how to send that token to another address.

For example, suppose I own some Melon (MLN) and want to check how much I have. I've been doing as follows:

var tokenContractABI = [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"minter","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"newAddress","type":"address"}],"name":"changeMelonportAddress","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"sender","type":"address"},{"name":"recipient","type":"address"},{"name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"endTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"MAX_TOTAL_TOKEN_AMOUNT_OFFERED_TO_PUBLIC","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"newAddress","type":"address"}],"name":"changeMintingAddress","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"lockedBalanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"startTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"recipient","type":"address"},{"name":"amount","type":"uint256"}],"name":"mintIcedToken","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"recipient","type":"address"},{"name":"amount","type":"uint256"}],"name":"mintLiquidToken","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"MAX_TOTAL_TOKEN_AMOUNT","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"recipient","type":"address"},{"name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"recipient","type":"address"}],"name":"unlockBalance","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"melonport","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"THAWING_DURATION","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"setMinter","type":"address"},{"name":"setMelonport","type":"address"},{"name":"setStartTime","type":"uint256"},{"name":"setEndTime","type":"uint256"}],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":true,"name":"_to","type":"address"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_spender","type":"address"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"Approval","type":"event"}] // melon contract ABI

var tokenContract = eth.contract(tokenContractABI).at("0xbeb9ef514a379b997e0798fdcc901ee474b6d9a1") // this is the melon contract address

tokenContract.balanceOf(eth.coinbase) // check balance

This seems like an overly clunky way to find out the balance of MLN in my account. Is there anything cleaner that can be done? Beyond that, I want to send MLN tokens to another address now, but it's not clear to me how to do that.

Thanks for help.

1

2 Answers 2

2

If you are using Ethereum wallet, the cleaner way is to `Watch Token

  • Go to contracts Tab.
  • Click on Watch Token
  • Enter details like Token Contract Address, Token Name, Token Symbol, Decimal Places of smallest unit
  • Click Ok

And you will be able to see balances.

To execute functions of the contract like 'transfer, you need to Watch Contract.

  • Go to contracts Tab.
  • Click on Watch Token
  • Enter details like Contract Name, Contract Address, JSON Interface (Contract ABI)
  • Click Ok
  • Now the contract will be listed under contracts tab and you can call any of it's functions

If you are not using Ethereum wallet and want to continue using geth, probably you should write functions for the actions like checkBalance, transferCoin using web3.js.

0

QuickBlocks has a command line tool called getTokenBal which takes as its first parameter any ERC20 token address followed by any number of additional accounts. It reports on token balances for each account after the first. From the command line,

getTokenBal 0xbeb9ef514a379b997e0798fdcc901ee474b6d9a1 <your_account>

would return your holdings in MLN (or any ERC20 token).

Alternatively, option --byAcct, takes an arbitrary number of ERC20 token addresses followed by an account and reports on token balances for each token for that account.

In normal operation, it runs against a locally running node, but there's an environment variable that you can set that causes it to look to Infura for its RPC source, so you don't have to download the entire blockchain.

A sister command line tool, called getBalance, works similarly but reports ETH balances.

[Full disclosure: I wrote QuickBlocks which is entering beta testing this week.]

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.