简体   繁体   English

比特币-红宝石宝石每次生成相同的地址?

[英]Bitcoin-ruby gem generating same address every time?

I am trying to use the bitcoin-ruby gem to create a new address for payment transactions from my public Bitcoin Address. 我正在尝试使用bitcoin-ruby gem从我的公开比特币地址创建用于支付交易的新地址。

I am able to use the pubkey_to_address method to do this. 我可以使用pubkey_to_address方法来执行此操作。 However, each time I run the method the resulting address, payment_address , is the same. 但是,每次我运行该方法时,结果地址payment_address都是相同的。 Services such as blockchain.info return a different address each time which is more consistent with my requirement. 每次诸如blockchain.info之类的服务都会返回一个不同的地址,这与我的要求更加一致。

Bitcoin-ruby github reference 比特币红宝石github参考

https://github.com/lian/bitcoin-ruby/blob/master/lib/bitcoin.rb#L128 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"

With @Thilo's feedback I now understand this. 有了@Thilo的反馈,我现在明白了。 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. 正如Thilo所指出的,我应该为每个事务使用新的pub / priv键,并尽可能使私钥处于脱机状态。 This priv key can then be used for future Bitcoin transactions against funds paid to the public address. 然后,此私钥可用于将来的比特币交易,而无需支付支付给公共地址的资金。

I'm getting there.. thanks 我要去那里..谢谢

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. 让我知道这是否行不通。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM