Bitcoin-ruby gem generating same address every time?

∥☆過路亽.° 提交于 2019-12-13 02:13:22

问题


I am trying to use the bitcoin-ruby gem to create a new address for payment transactions from my public Bitcoin Address.

I am able to use the pubkey_to_address method to do this. However, each time I run the method the resulting address, payment_address, is the same. Services such as blockchain.info return a different address each time which is more consistent with my requirement.

Bitcoin-ruby github reference

https://github.com/lian/bitcoin-ruby/blob/master/lib/bitcoin.rb#L128

My Code is below

require 'bitcoin'

ORIGIN_ADDRESS = "1BjxMfaBpsXu8AnAA44TTgopWuE6QamvCQ"
payment_address = Bitcoin::pubkey_to_address(ORIGIN_ADDRESS)
puts payment_address
# => "171GYkox1rWqNf8skyK2Aw9EAnVJ1wPwKf"

回答1:


With @Thilo's feedback I now understand this. The services that I had been using were abstracting the fact that the were generating new "receiver" address with new private key that automatically forwards back to the Bitcoin address I provided them when a transaction was confirmed on block chain.

As Thilo points out, I should use new pub/priv key for each transaction and keep the priv key offline if at all possible. This priv key can then be used for future Bitcoin transactions against funds paid to the public address.

I'm getting there.. thanks




回答2:


I had a similar issue to what you had. Try doing this:

 def gen_address
   ORIGIN_ADDRESS = "1BjxMfaBpsXu8AnAA44TTgopWuE6QamvCQ"
   return Bitcoin::pubkey_to_address(ORIGIN_ADDRESS)
 end
 puts gen_address()

(There might be a syntax error, but the code should be something like this).

Let me know if this doesnt work.



来源:https://stackoverflow.com/questions/24031323/bitcoin-ruby-gem-generating-same-address-every-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!