2

(web3js)

Let's say I have the below data (specifications here).

{ 
    ...
    hash: '0x86bc6fef9a3009f377a3a66b7fa654b3e498f4af46c297eab86346b3e5eabd7c',
    nonce: '0x2ed', 
    value: '0x0',
    type: '0x0',
    v: '0x93',
    r: '0xf17ebf8bea51ea280883ed8be3efa0112669820993e29a6b5fbbededd57f97d',
    s: '0x5dda51842d1ed1c81e8716ae25ffc389ec17c2eb1c67e74e092802d9339366e8'
}

I have 2 questions:

  1. Can anyone say what are type/value/v/r/s values? I was unable to find their meanings.

  2. How to decode them ? (I am able to decode other numeric values with Web3.utils.hexToNumber)

T.Todua
  • 155
  • 1
  • 10
  • https://ethereum.stackexchange.com/questions/15766/what-does-v-r-s-in-eth-gettransactionbyhash-mean – Majd TL Dec 03 '21 at 08:35
  • @MajdTL thanks, that almost answers my question. the only remaining question/matter for me now , is 'value' and 'type' being always 0x0. – T.Todua Dec 03 '21 at 09:52
  • value is the amount of transferred ether (not fee) with the transaction. you are probably not sending any ether so it is hex 0x0 -> 0 and type I think it is the type of the transaction and seems to be always 0 for your transactions -> https://eips.ethereum.org/EIPS/eip-2718 – Majd TL Dec 03 '21 at 10:39

1 Answers1

1

Can anyone say what they are?

  • hash: is the Keccak-256 hash of the signed and encoded transaction.
  • nonce: is a number incremented by the signer for each transaction, like a counter of all transactions belonging to an account.
  • value: the amount of Ether (in Wei) you want to send.
  • type: (this must be some internal variable of the core-geth tx pool)
  • v: it's the signature's v value used to recover the signature's recovery id later (also called y-parity).
  • r: the actual signature (r).
  • s: the actual signature (s).

How to decode them?

  • The hash cannot be decoded, it's a one-way action.
  • Nonce, value, type can be just converted to numerics if you prefer.

The signature is usually concatenated:

"#{r}#{s}#{v}"
# => "f17ebf8bea51ea280883ed8be3efa0112669820993e29a6b5fbbededd57f97d5dda51842d1ed1c81e8716ae25ffc389ec17c2eb1c67e74e092802d9339366e893"

To recover the y-parity from v, you would need the chain ID the transaction was broadcasted on:

    # Convert a given `v` value to an ECDSA recovery id for the given
    # EIP-155 chain ID.
    #
    # @param v [Integer] the signature's `v` value
    # @param chain_id [Integer] the chain id the signature was generated on.
    # @return [Integer] the recovery id corresponding to `v`.
    # @raise [ArgumentError] if the given `v` is invalid.
    def to_recovery_id(v, chain_id = ETHEREUM)
      e = 0 + 2 * chain_id + 35
      i = 1 + 2 * chain_id + 35
      if [0, 1].include? v
    # some wallets are using a `v` of 0 or 1 (ledger)
    return v
  elsif is_legacy? v

    # this is the pre-EIP-155 legacy case
    return v - 27
  elsif [e, i].include? v

    # this is the EIP-155 case
    return v - 35 - 2 * chain_id
  else
    raise ArgumentError, "Invalid v #{v} value for chain ID #{chain_id}. Invalid chain ID?"
  end
end

Assuming, you are working on Binance Smart Chain (56):

Eth::Chain.to_recovery_id 0x93, 56
=> 0

(used the ruby eth gem: https://github.com/q9f/eth.rb/blob/33b757c34c53200645444eb8f8797376ae304bb9/lib/eth/chain.rb#L99)

q9f
  • 32,913
  • 47
  • 156
  • 395
  • thanks for sharing your inputs here. Sorry for reaching you out of the blue. I was wondering if you could assist me with this. I am kind of not finding any information anywhere else. https://ethereum.stackexchange.com/questions/118130/swap-for-tokens-with-bot-protection-enabled-bpenabled Thanks a ton in advance. – Amith Kumar Jan 06 '22 at 21:56