2

I need to send ERC20 tokens (golem to be precise) in an automated manner, so I set up a geth json-rpc server with

./geth --fast --rpc

So I can call the api just fine.

The documentation for eth_sendtransaction makes it easy to send ethereum to another address, but I couldn't find how to send ERC20 tokens. I saw the data field which allowed to trigger a smart contracts. So I suppose I need to trigger a function within the smart contract of the ERC20 token but since I would need to learn solidity and read through the whole golem smart contract I thought I'd ask here first.

Thanks !

  • Since Golem is an ERC20 compliant token, then you need to call the standard transfer() function on the smart contract to transfer x tokens to y address. The function is as follows: transfer(address _to, uint256 _value). – ʰᵈˑ Sep 18 '17 at 11:21
3

To send ERC20 compliant token you need to call method transfer of contract. To do this with geth you correctly have chosen eth_sendTransaction RPC Call.

In data parameter you should specify ABI-encoded function transfer with parameters encoded as described here (ABI-encoded).

To encode parameters you may want to use online tool https://abi.hashex.org. You enter name of function (transfer) and add parameters with types and values. Or you can just paste in token abi and pick function transfer in dropdown list "Function type". Here is example of using this tool.

enter image description here

There is also a javascript library to encode parameters if you want to do this automatically.

After you got your ABI-encoded data, you set it to data field in Geth RPC call, set other values and you are ready to call Geth and transfer tokens.

Pay attention to that account your are sending tokens from (from parameter in RPC call) should be unlocked in Geth to sign transaction.

1

If you are fine with using a REST API, you could make use of Tokengateway, which allows to automatically send and receive any ERC20 token. This way you don't need to learn Solidity.

0

Thanks, tried your method and it did transfer, ETH and not the token. How and where do we define the contract address (so that it knows the ABI belongs to the contract) so that we can send the correct token.

<-- EDIT -->

Just found the solution: To: the address of the token contract, since that's the recipient of the function invocation.

value = 0 (amount of ethereum to be sent.)

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.