I'm trying to call Smart Contract with next method signature


and Code like:

function calculateHash( string testStr ) constant returns ( bytes32 ){
    return sha3( testStr );

I have next Sha3: 0xa8cbcecd37e0c4ac16c3135987b900352c43486006715fbca927444ab937b3af so first 4 bytes looks like 0xa8cbcecd Parameter for example is "Hello, Words!" According to ABI documentation I should encocde it like

bytes, of length k (which is assumed to be of type uint256):

enc(X) = enc(k) pad_right(X), i.e. the number of bytes is encoded as a uint256 followed by the actual value of X as a byte sequence, followed by the minimum number of zero-bytes such that len(enc(X)) is a multiple of 32.


enc(X) = enc(enc_utf8(X)), i.e. X is utf-8 encoded and this value is interpreted as of bytes type and encoded further. Note that the length used in this subsequent encoding is the number of bytes of the utf-8 encoded string, not its number of characters.

so in my case it is

enc(enc_utf8("Hello, World!)) = end(Ox48656c6c6f2c20576f726c6421) = 

so full POST looks like


But I have next return {
    "jsonrpc": "2.0",
    "result": "0x",
    "id": 2

Where is my mistake? Thank you Alex


the problem was fixed, I forgot about offset for dynamic parameters So encoding was correct 000000000000000000000000000000000000000000000000000000000000000d 48656c6c6f2c20576f726c642100000000000000000000000000000000000000 but I have to add next to start after method signature 0000000000000000000000000000000000000000000000000000000000000020 so full part looks like

0000000000000000000000000000000000000000000000000000000000000020 000000000000000000000000000000000000000000000000000000000000000d 48656c6c6f2c20576f726c642100000000000000000000000000000000000000 a little strange, but working

  • Remember to come back in a couple of days and accept your own answer :-) (There's a 48-hour delay before you can.) – Richard Horrocks Jul 2 '17 at 13:12

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.