0

I found only one semi-automatic solution to transfer tokens from one wallet to another.

But i want to do that by web3js way on ruby stack. Could you guys explain me, how exatly to get data for eth_sendTransaction data field with no using web3js (contract.transfer.getData("0xCb...", 10, {from: "0x26..."})).

UPD.

I got the point about components of data.

For example let's get transaction 0xd21fa94958692c0aa3523ae9e8984067976483ec57642554a1dda0417e3337e2

Input data:

MethodID: 0xa9059cbb [0]: 000000000000000000000000c1816acca0a3a120fc980c58cb485d41f2b30e8e 1: 0000000000000000000000000000000000000000000000000000000000007530

  1. So, MethodID is encrypted function by keccak256. By than i am trying to get this result by same logic:

Digest::SHA3.new(256).digest('transfer(address,uint256)') => "\xA9\x05\x9C\xBB*\xB0\x9E\xB2\x19X?JY\xA5\xD0b:\xDE4m\x96+\xCDNF\xB1\x1D\xA0G\xC9\x04\x9B"

Why do I get different resultsЮ

  1. Second parameter is address (000000000000000000000000c1816AcCA0a3A120fc980c58CB485D41F2B30E8e). Original one is 0xc1816AcCA0a3A120fc980c58CB485D41F2B30E8e. Next we trim few hex chars and what we should do next to generate same result?

  2. And last param is amount. What should we do to convert 3 tokens to 0000000000000000000000000000000000000000000000000000000000007530.

0

The first four bytes of the data field should be the function selector. The function selector is the first four bytes of the keccak-256 hash of the canonical function signature. In this case, keccak256("transfer(address,uint256)") (0xa9059cbb).

The next 32 bytes should be the address (left-padded) you're transferring to, and the 32 bytes after that should be the amount.

EDIT

Based on further questions in the edited question.

  1. It looks like you're using SHA3 instead of keccak-256.
  2. I'm not sure what your question here is.
  3. 0x7530 == 30000. If that's "3" tokens, then the token is using four decimal places. (3 * 10^4 == 30000 == 0x7530.)
  • Thanks for answer buddy. And I'm sorry, because for me it's still part of magic box. Updated the question. – Doniv Mar 15 '18 at 12:26
  • Please see my edit. – smarx Mar 15 '18 at 12:37
  • 1. It should be same github.com/phusion/digest-sha3-ruby. But in any case i can handle this. 2-3. I forgot about decimals, not all is clear. I really appreciate your help. – Doniv Mar 15 '18 at 14:55

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.