Having an issue with signing a message for the DDEX api... I'm trying to do it in python, and for some reason my signature is off by two characters. Here's my code using the private key and UTC timestamp in the docs.

import web3
from eth_keys import keys
from web3.auto import w3
from eth_utils import decode_hex
from eth_account.messages import encode_defunct
private_key_0 = "0xe4abcbf75d38cf61c4fde0ade1148f90376616f5233b7c1fef2a78c5992a9a50"

# Testing the Auth function...
epoch_time = "1524088776656"
message = "HYDRO-AUTHENTICATION@1524088776656"

message_bytes = ''.join(hex(ord(c)) for c in message)
message_hex = b'{message_bytes}'.hex()

priv_key_bytes = decode_hex(private_key_0)
priv_key = keys.PrivateKey(priv_key_bytes)
pub_key = priv_key.public_key

public_address_0 = pub_key.to_checksum_address()
print("PUBLIC KEY: " + public_address_0)
print("PRIVATE KEY: " +private_key_0)

# print("Message hex: " +message_hex)
msg = encode_defunct(text=message.rstrip())
signed_message = w3.eth.account.sign_message(msg,private_key=private_key_0)

sig = signed_message['signature']

# test should be:
# 0x603efd7241bfb6c61f4330facee0f7027d98e030ef241ad03a372638c317859a50620dacee177b771ce05812770a637c4c7395da0042c94250f86fb52472f93500 
# but is: 
# 0x603efd7241bfb6c61f4330facee0f7027d98e030ef241ad03a372638c317859a50620dacee177b771ce05812770a637c4c7395da0042c94250f86fb52472f9351b
test = str(sig.hex())

header = str(public_address_0) + "#" + message + "#" + test 


I've gotten here because I was getting an "unauthorized" error from the DDEX api when I've been trying with my own private key. I figure it has to be something to do with the signature function, but can't quite figure it out... any ideas?

1 Answer 1


Ethereum expects the v component of a signature (the last byte) to be 27 or 28, rather than 0 or 1. You can just add 27 (0x1b) to that last byte.

  • I see! Thanks a bunch, for those who may have similar issues with python I used ` yumBites = bytes.fromhex(str(sig.hex())[2:]) # get rid of 0x holdBites = yumBites[:-1] endBites = yumBites[-1] + 27 finalBites = holdBites + bytes(endBites) finalFinal = finalBites[:-53]`
    – Trade Alot
    Commented Sep 25, 2019 at 3:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.