当前位置:  软件>JavaScript软件

BitcoinJS

    来源:    发布时间:2014-12-24

    本文导语:  BitcoinJS 是一个纯 JavaScript 库,支持 Node.js 和浏览器,用于操作各种比特币钱包。 Features Clean - Pure JavaScript, concise code, easy to read. Tested - Coverage > 95%, third-party integration tests. Careful - Two person approval process for small, focused pull requests....

BitcoinJS 是一个纯 JavaScript 库,支持 Node.js 和浏览器,用于操作各种比特币钱包。

BitcoinJS[图片]

Features
  • Clean - Pure JavaScript, concise code, easy to read.

  • Tested - Coverage > 95%, third-party integration tests.

  • Careful - Two person approval process for small, focused pull requests.

  • Compatible - Works on Node.js and all modern browsers.

  • Powerful - Support for advanced features, such as multi-sig, HD Wallets.

  • Secure - Strong random number generation, PGP signed releases, trusted developers.

  • Principled - No support for browsers with crap RNG (IE < 11)

  • Standardized - Node community coding style, Browserify, Node's stdlib and Buffers.

  • Fast - Optimized code, uses typed arrays instead of byte arrays for performance.

  • Experiment-friendly - Bitcoin Mainnet and Testnet support.

  • Altcoin-ready - Capable of working with bitcoin-derived currencies (such as Dogecoin).

示例代码:

//生成比特币地址
key = Bitcoin.ECKey.makeRandom()

// Print your private key (in WIF format)
console.log(key.toWIF())
// => 8c112cf628362ecf4d482f68af2dbb50c8a2cb90d226215de925417aa9336a48

// Print your public key (toString defaults to a Bitcoin address)
console.log(key.pub.getAddress().toString())
// => 14bZ7YWde4KdRb5YN7GYkToz3EHVCvRxkF

//开始交易
tx = new Bitcoin.Transaction()

// Add the input (who is paying) of the form [previous transaction hash, index of the output to use]
tx.addInput("aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31", 0)

// Add the output (who to pay to) of the form [payee's address, amount in satoshis]
tx.addOutput("1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK", 15000)

// Initialize a private key using WIF
key = Bitcoin.ECKey.fromWIF("L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy")

// Sign the first input with the new key
tx.sign(0, key)

// Print transaction serialized as hex
console.log(tx.serializeHex())
// => 0100000001313eb630b128102b60241ca895f1d0ffca21 ...

// You could now push the transaction onto the Bitcoin network manually (see https://blockchain.info/pushtx)



    
 
 

您可能感兴趣的文章:

 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3