Moon soon
Moon soon

Reputation: 2856

go-ethereum encoding or decoding input data without abi

In web3.js, I can decode input parameters without abi:

const data = web3.eth.abi.decodeParameters(
    ["uint256", "uint256", "address[]", "address", "uint256"],
    "000000000000000000000000000000000000000000000001885c663d0035bce200000000000000000000000000000000000000000000000000f5666f7fdaa62600000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000c0be713b48822271b362e9fac00479f5134172e80000000000000000000000000000000000000000000000000000000060e93fa900000000000000000000000000000000000000000000000000000000000000020000000000000000000000009813037ee2218799597d83d4a5b6f3b6778218d9000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
);

returns

Result {
  '0': '28272584972907691234',
  '1': '69073998366549542',
  '2': [
    '0x9813037ee2218799597d83D4a5B6F3b6778218d9',
    '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'
  ],
  '3': '0xc0Be713B48822271b362e9Fac00479f5134172e8',
  '4': '1625898921',
  __length__: 5
}

And we can encode with following:

web3.eth.abi.encodeFunctionCall({
    name: 'myMethod',
    type: 'function',
    inputs: [{
        type: 'uint256',
        name: 'myNumber'
    },{
        type: 'string',
        name: 'myString'
    }]
}, ['2345675643', 'Hello!%']);
> "0x24ee0097000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000"

Is there a similar method for go-ethereum for decoding and encoding without abi?

Upvotes: 2

Views: 2236

Answers (1)

Mohamed Sohail
Mohamed Sohail

Reputation: 1867

decoding and encoding without abi?

Not possible, in fact in your example you know part of the ABI i.e. ["uint256", "uint256", "address[]", "address", "uint256"] to decode a certain params. In your second example you also know the fucntion signature to encode.

There is a service called https://www.4byte.directory/signatures/ that has a huge list of crowd sourced signatures that can allow you to index txs which could match those signatures or decode events without knowing the ABI.

As for interacting with an ABI in go:

With geth aka go-ethereum I usually see most people use abigen (examples there)

I personally prefer a lmittmann/w3 which can decode and encode similarly like your examples above.

Upvotes: 3

Related Questions