I'm working with rarible API and for one request it's needed to provide a signature as a string.

I have a signature object { "v": 28, "r": "0xda4429a9e8e6b54cb101b2df002039f2879ab4ca0e8fae64134942cb81f3e581", "s": "0x3b90a37dc078a82dfc418695b1d4473661aa4d24dd874ac68678894ff44a6b27" }

How can I turn this object into a signature string?


You can get this and more information by looking up RLP Encoding in Ethereum's Yellow Paper, as is explained here. To directly answer your question for your case:

Signature format is v ++ (length(r) + 0x80 ) ++ r ++ (length(s) + 0x80) ++ s, where + means addition and ++ means concatenation. Notice that length here means the amount of bytes, so that means the amount of symbols in hex divided by two.

In your case, this would lead to

0x28 ++ (0x20 + 0x80) ++ 0xda4429a9e8e6b54cb101b2df002039f2879ab4ca0e8fae64134942cb81f3e581 ++  (0x20 + 0x80) ++ 0x3b90a37dc078a82dfc418695b1d4473661aa4d24dd874ac68678894ff44a6b27

and result in the following signature string:


Notice how I am implicitly assuming your provided v is already in hex format although it does not start with 0x. If this result differs from your expectation, try converting v to its hex representation and following the same process I just described with the converted value.

  • Thank you for your detailed response. It helps a lot. When I plug your result the API claims that it's too long. Invalid signature size 67, should be 65 bytes Any clue how to reduce the size but keep the signature? I think Rarible expects a certain format. I wish they had an example request, but I can't find anything like that
    – NICK TOE
    Aug 23 at 16:36
  • My original answers refers to signatures for signed transactions. It could be that Rarible wants just normal ECDSA signatures, in which case your signature is just r ++ s ++ v. Aug 24 at 17:57
  • Let me know if this turned out to be the case and I will edit my original answer accordingly Aug 24 at 20:07
  • Turned out rarible have their own way to deal with signatures. They just conc the values. Thank you for your help 🙏
    – NICK TOE
    Sep 3 at 9:26

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.