4

Reading my input data on etherscan, I see each value as hex values. Which is fine to read the addresses. But I would like to read the amounts [1] && [3] as numbers.

Contract Method

Function: trade(address tokenGet, uint256 amountGet, address tokenGive, uint256 amountGive, uint256 expires, uint256 nonce, address user, uint8 v, bytes32 r, bytes32 s, uint256 amount)

input data

MethodID: 0x0a19b14a
[0]:0000000000000000000000000000000000000000000000000000000000000000
[1]:000000000000000000000000000000000000000000000016d8fceafcef3c0000
[2]:000000000000000000000000340d2bde5eb28c1eed91b2f790723e3b160613b7
[3]:00000000000000000000000000000000000000000008b7363b040ca2bb600000

I made a transaction etherdelta where I bought 25 tokens. So the expected transformed value of the input data [1] should be 25 or 25 * 10^18 (in wei) or at least any multiple of 25*10^x.

Question

How to convert the hex to the expected value?

Tries

  1. Using https://github.com/miguelmota/ethereum-input-data-decoder shows me the same values as on etherscan.io

  2. converting to Ascii gives garbage (as recommended here: How to decode input data from a transaction?)

  3. web3.utils.hexToNumberString & web3.utils.hexToNumber err

  4. console.log(0x000000000000000000000000000000000000000000000016d8fceafcef3c0000) shows some arbitrary value

  • Do you have the transaction id? – Ismael Nov 28 '17 at 18:06
5

From Miguel Mota page, using Etherdelta ABI, and your transaction input I get

{
  "name": "trade",
  "types": [ .. ],
  "inputs": [
    "0",
    "16d8fceafcef3c0000",      // <- amountGet
    "340d2bde5eb28c1eed91b2f790723e3b160613b7",
    "8b7363b040ca2bb600000",   // <- amountGive
    "46eeac",
    "87d84d79",
    "14ce500a86f1e3ace039571e657783e069643617",
    "1c",
    {
      "type": "Buffer",
      "data": [..]
    },
    {
      "type": "Buffer",
      "data": [..]
    },
    "38d7ea4c68000"            // <- amount
  ]
}

The commented values are those used to calculate what you receive. This is done in Ethedeleta tradeBalances function

  function tradeBalances(address tokenGet, uint amountGet, 
      address tokenGive, uint amountGive, 
      address user, uint amount) private {
    ...
    tokens[tokenGive][msg.sender] = 
       safeAdd(tokens[tokenGive][msg.sender], 
       safeMul(amountGive, amount) / amountGet);
  }

You should receive amountGive * amount / amountGet

0x8b7363b040ca2bb600000 * 0x38d7ea4c68000 / 0x16d8fceafcef3c0000 25000000000000000000L = 25*10^18

Which is what you expected.

  • 1
    Ok, the calculation is indeed correct. amount is actually the amount I spend 0.001 eth. amountGive/amountGet is basically the price. I'm still puzzled what amountGive and amountGetis. According to the [overview ](reddit.com/r/EtherDelta/comments/6kdiyl/smart_contract_overview) they should be the amount (in my case 25x10^18 & 4x10^10). > amountGet and amountGive represent the size and price you want to trade – Andi Giga Nov 28 '17 at 19:11
  • I'm not an Etherdelta expert, but I'd guess they are the original offer amounts, you only buy less than the total to sell. – Ismael Nov 28 '17 at 19:16

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.