Blockchain

如何生成比特幣地址?

  • September 18, 2020

除了區塊鏈 API,還有什麼方法可以生成比特幣地址嗎?(鑑於它不公開)

我寫了一個長而詳細的教程<http://procbits.com/2013/08/27/generating-a-bitcoin-address-with-javascript>

簡而言之,一直向下滾動到摘要以查看此簡短版本:

var randArr = new Uint8Array(32) //create a typed array of 32 bytes (256 bits)
window.crypto.getRandomValues(randArr) //populate array with cryptographically secure random numbers

//some Bitcoin and Crypto methods don't like Uint8Array for input. They expect regular JS arrays.
var privateKeyBytes = []
for (var i = 0; i &lt; randArr.length; ++i)
 privateKeyBytes[i] = randArr[i]

var eckey = new Bitcoin.ECKey(privateKeyBytes)
eckey.compressed = true
var address = eckey.getBitcoinAddress().toString()
console.log(address)// 1FkKMsKNJqWSDvTvETqcCeHcUQQ64kSC6s

var privateKeyBytesCompressed = privateKeyBytes.slice(0) //clone array
privateKeyBytesCompressed.push(0x01)
var privateKeyWIFCompressed = new Bitcoin.Address(privateKeyBytesCompressed)
privateKeyWIFCompressed.version = 0x80
privateKeyWIFCompressed = privateKeyWIFCompressed.toString()

打開頁面上的 JavaScript 控制台(在您的瀏覽器中)並繼續操作。您可以在瀏覽器中創建自己的地址。我不建議使用這個新創建的地址來實際進行商業活動。只需將其用作學術練習。

引用自:https://bitcoin.stackexchange.com/questions/17751