It seems like depending on the method you get different public keys and addresses when using bitcoin-ruby with the same private key. I am probably doing something wrong, but I am not sure where it is...

I can generate a private key, public key, and address using

def generate_address
  private_key, public_key = Bitcoin::generate_key
  address = Bitcoin::pubkey_to_address(public_key)
  [private_key, public_key, address]

And, as an example, this could generate:

priv_key= "9d524654045c891327a1dc0c329bcd42311b1767b81d7e997486e841ca5a2a87"
publ_key = "04353457464a32ede1b80fd7299f616320b52cc22796cd27d5b41594f418c2ea26dfeec97273f89b2d908a44fce981ff19f2e2de1408538bb0c0528992ce47f3be"
address = "n1693JDDu5ukbtNh2sHXdZSobKnVEpdtjL"

However, if I then put the private key into another function which generates the key details in a different way, I get a different address! Why is this?

def key_details(prikey)
  #returns prikey, prikey_hash58, pubkey_hash58, pubkey_uncompressed, address as a hash
  my_key = Bitcoin::Key.new(prikey)
  # binding.pry
  { prikey:prikey, 
    pubkey: my_key.pub_uncompressed, 

1 Answer 1


The difference is that the first function uses uncompressed public keys , and the second function uses compressed public keys. Uncompressed public keys are 65 bytes , and compressed ones are 33 bytes.

For more information on compressed public keys see: What is a compressed Bitcoin key?

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.