3

I want to transfer ERC20 (standard) tokens from a basic ethereum account to an exchange or to another account. How do I do that without using a GUI like Mist?

7

Step 0: Install geth, start geth (with "--unlock 0xYOURACCOUNT"), sync the blockchain, open up a geth terminal in another window with "geth attach".

Step 1: Save the ERC20 ABI to a variable. This is the interface for interacting with the token contract.

var omisegoAbi = [{"constant":true,"inputs":[],"name":"mintingFinished","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"unpause","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"mint","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"finishMinting","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"pause","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"},{"name":"_releaseTime","type":"uint256"}],"name":"mintTimelocked","outputs":[{"name":"","type":"address"}],"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":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[],"name":"MintFinished","type":"event"},{"anonymous":false,"inputs":[],"name":"Pause","type":"event"},{"anonymous":false,"inputs":[],"name":"Unpause","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"},{"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"}];

Step 2: Create the contract variable using the web3 contract method:

var omisegoContract = web3.eth.contract(omisegoAbi).at('0xd26114cd6EE289AccF82350c8d8487fedB8A0C07'); // 0xd26114cd6EE289AccF82350c8d8487fedB8A0C07 is the omisego contract addr. Other tokens will have different addresses

Optional step, check an account balance (# of OMG tokens for this acct):

web3.fromWei(omisegoContract.balanceOf("0xYOURACCOUNT"),"ether");

or check all of your accounts in the .ethereum/keystore directory

eth.accounts.forEach(function(e,i){console.log("eth.accounts["+i+"]: " + "\tbalance:" + web3.fromWei(omisegoContract.balanceOf(eth.accounts[i]),"ether") + " OMG")})

Step 3: Send a small amount of the token (here, 1) to the destination address.

omisegoContract.transfer("0xDESTINATIONADDRESS",web3.toWei(1,"ether"),{from:"0xGASPAYINGADDRESS"});// here, 0xGASPAYINGADDRESS is the account from which to pay gas to make this tx. Probably the same as the source address.

Step 4: Transfer the rest. Same command as above with a greater value

  • 2
    I've been looking all over the web for this. Thank you so much. – e18r Sep 27 '17 at 3:28
  • You are my hero and I love you – Barney Chambers May 29 at 1:21
0

This is awesome, but for some reason its trying to send all the tokens. Where do you control the amount? ,web3.toWei(1,"ether") isn't this part for the ether payment?

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.