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.

| improve this answer | |

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.