BitcoinJS是一个纯JavaScript库,支持Node.js和浏览器,用于操作各种比特币钱包。
特性干净--纯JavaScript,代码简洁,易于阅读。经过测试--覆盖率>95%,第三方集成测试。谨慎-对于小型的、集中的拉取请求,有两个人的审批流程。兼容--可在Node.js和所有现代浏览器上工作。强大--支持高级功能,如多签、高清钱包。安全--强大的随机数生成,PGP签名发布,值得信赖的开发者。原则性--不支持垃圾RNG的浏览器(IE<11)。标准化--Node社区编码风格,Browserify,Node的stdlib和Buffers。快速-优化的代码,使用类型化数组代替字节数组以提高性能。实验友好-支持BitcoinMainnet和Testnet。Altcoin-ready-能够与比特币衍生货币(如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 WIFkey = Bitcoin.ECKey.fromWIF("L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy")// Sign the first input with the new keytx.sign(0, key)// Print transaction serialized as hexconsole.log(tx.serializeHex())// => 0100000001313eb630b128102b60241ca895f1d0ffca21 ...// You could now push the transaction onto the Bitcoin network manually (see https://blockchain.info/pushtx)
评论