I'm trying to generate ethereum raw transactions.

this is keccak hash of my transaction:


after signing it with my private key I obtained this values:

r= 4041e0cf580308bcedc1f0a136029ff5200827f9dacad8c3b4884ab1350c031f
s= 0e0a5e601489fbd5a647e0423f0cf84c80b7d14cb3bf61e066184b2d94c7a267

now at the end I must calculate value of v

I found two formulas for it:

1) v = CHAIN_ID * 2 + 35
2) v = CHAIN_ID * 2 + 36

I don't know which formulas must I use.

now exactly how must I detect which formulas must I use ?


For the library you're using, see https://github.com/simplito/elliptic-php/blob/d6c5ecaaf434a52449f5e8faa350311c9fd1dd7a/tests/ECDSATest.php#L305:

$recid = $ec->getKeyRecoveryParam($msg, $signature, $key->getPublic());

Or perhaps $recoverParam is already a member of Signature? See https://github.com/simplito/elliptic-php/blob/master/lib/EC/Signature.php#L12.

In any case, I imagine that the recovery param is 0 or 1. You'll need to add to it to get the right v value for the chain you're using.

  • $recoverParam is always member of Signature and always return me 0 . now what must I add to it ? – saeid ezzati Aug 26 '18 at 19:32
  • It might help to look at the code for ethereumjs-tx: github.com/ethereumjs/ethereumjs-tx/blob/master/index.js#L146 for where to include the chain ID in the transaction before RLP encoding and hashing, and github.com/ethereumjs/ethereumjs-tx/blob/master/index.js#L231 for what to add to the recovery bit to get the right v value. – smarx Aug 26 '18 at 19:36
  • value of $recoverParam for me always is 0 and according to your link, value of v always is 10 for me. but in EIP-155 says that value of v always must be 37 or 38 – saeid ezzati Aug 26 '18 at 19:46
  • ethUtil.ecsign already adds 27 to the recovery value, so adding 10 more would give you 37 or 38. – smarx Aug 26 '18 at 19:51
  • ok. so first I must add 27 to $recoverParam and put it in v and then do this: v += CHAIN_ID * 2 +8 that gives me 37 . so the final value of v is 37 :) – saeid ezzati Aug 26 '18 at 20:04

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.