2

I'm running truffle's default example Metacoin:

import "ConvertLib.sol";

contract MetaCoin {
  mapping (address => uint) balances;

  function MetaCoin() {
    balances[tx.origin] = 10000;
  }

  function sendCoin(address receiver, uint amount) returns(bool sufficient) {
    if (balances[msg.sender] < amount) return false;
    balances[msg.sender] -= amount;
    balances[receiver] += amount;
    return true;
  }

  function getBalanceInEth(address addr) returns(uint){
    return ConvertLib.convert(getBalance(addr),2);
  }

  function getBalance(address addr) returns(uint) {
    return balances[addr];
  }
}

When I run the application and send some coins, it generates the following payload:

{
    "jsonrpc": "2.0",
    "method": "eth_sendTransaction",
    "params": [{
        "from":"0x86b737b44e4b04d92ff7ee7b5604cc755e2c1124",
        "to":"0xea1ab86f57e0faccca14510d883cc660d5453995",
        "data":"0x90b98a11000000000000000000000000914e95d7b57c1899f0a77fb1f08a9ae02b01258200000000000000000000000000000000000000000000000000000000000000ff"
    }],
    "id":38
}

I've sent 255 Meta to address 0x914e95d7b57c1899f0a77fb1f08a9ae02b012582 calling sendCoin(). Then I was trying to understand the data payload, breaking it down:

?? 0x90b98a11000000000000000000000000

address to (20 Bytes) -> 914e95d7b57c1899f0a77fb1f08a9ae02b012582

uint value (32 Bytes) -> 00000000000000000000000000000000000000000000000000000000000000ff

The first part (16 Bytes) of the data payload I assume will identify the sendCoin method inside the deployed contract.

  1. If so, how?
  2. Do these 32 Bytes just identify the method name or can it be broken down even more?
3

You may want to check out the ABI specification, which specifies how call and return arguments are encoded.

  • "0xcdcd77c0: the Method ID. This is derived as the first 4 bytes of the Keccak hash of the ASCII form of the signature baz(uint32,bool)." Nice! But what about the remaining 12 Bytes containing all zeroes? – Henrique Barcelos Apr 13 '16 at 14:47
  • 1
    @HenriqueBarcelos The 0s are the leading 0s of the second argument, the address to which to send the coins. – Nick Johnson Apr 13 '16 at 15:13
  • That's what I thought, but why this happens? It seems like wasting data... – Henrique Barcelos Apr 13 '16 at 15:21
  • 1
    @HenriqueBarcelos The EVM word size is 32 bytes (256 bits) ethereum.stackexchange.com/q/2327/42 and is the natural unit of data: en.wikipedia.org/wiki/Word_(computer_architecture) – eth Apr 14 '16 at 4:35
  • Got it! Thank you... – Henrique Barcelos Apr 14 '16 at 13:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.