BitcoinJS

簡介:

操作相關bitcoin的API提供者

https://blockexplorer.com/api-ref

https://github.com/blockchain/service-my-wallet-v3 (此為跑在自己local端的server)

https://www.block.io/docs

https://blockchain.info/api/blockchain_api

https://chainquery.com/bitcoin-api/getinfo

https://github.com/bitcoinj/bitcoinj (Java寫的Bitcoin核心 也可使用Nashore來執行javascript)

https://www.smartbit.com.au/api

直接與本地的Bitcoind 啟動的JSON-RPC溝通

https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)

使用BitcoinJS

範例:

https://github.com/bitcoinjs/bitcoinjs-lib/blob/9bae30d1121a9d382f2f461fad0194a0e97dfd1e/test/integration/addresses.js

npm install bitcoinjs-lib

產生隨機地址

產生一組萊特幣的address跟WIF

之後可到此確認https://live.blockcypher.com/ltc/

把WIF格式的私鑰轉換為地址

產生多重簽章的地址2-of-3 multisig P2SH address

https://en.bitcoin.it/wiki/Multisignature

產生交易

產生較複雜的交易,並廣播到Bitcoin Test Network

之後會看到如下輸出

進入到此網站https://live.blockcypher.com/btc-testnet

然後在右上角輸入地址 即可查看剛才的交易紀錄(需要稍等一段時間)

一篇不錯的教學: https://medium.com/@orweinberger/how-to-create-a-raw-transaction-using-bitcoinjs-lib-1347a502a3a#.gbnwu2863

查看上次交易的Txid:

https://blockchain.info/

到上面網站的輸入框輸入你的比特幣地址即可看到

把產生的交易hex廣播到bitcoin network

先到

https://live.blockcypher.com/btc/pushtx/

(另外一個廣播交易的blockchain.info其廣播後的訊息較不明確,只會產生例如code=-25,-26等訊息,blockcypher會明確顯示原因)

1.貼上如下 (此為確實發生的以前交易,但unspend已經被花掉了)

接著

2.試看看如下

(此為確實發生的以前交易,已經發生過此交易,但unspend尚存在)

3.然後試著把一些字隨便改掉上按送出看看

Last updated

Was this helpful?