qtum 链接入

下面我们来说说qtum 链的接入

参考文档

https://github.com/qtumproject/qtum-web-wallet
https://github.com/bitcoinjs/bitcoinjs-lib
https://github.com/qtumproject/qtumjs-lib

web钱包介绍

https://github.com/qtumproject/qtum-web-wallet

启动
// 根据上面的地址下载项目
// 在项目根目录下执行如下操作
npm install
npm install qtumjs-lib
npm install bitcoinjs-lib
// 启动
npm run dev
// 如果这个出现包为安装,请自行安装
//默认的80 端口所以 打开浏览器 127.0.0.1 就可以看到效果了

项目目录介绍
image.png
image.png
总结

代码示例:

const qtum = require('qtumjs-lib')
const bip39 = require('bip39')
const abi = require('ethjs-abi')
const aes =  require('aes256')

let network = {}
const VERSION = '1.0'
var password = '123456'
 network = qtum.networks.qtum_testnet

var mnemonic = bip39.generateMnemonic()
console.log("助记词:" + mnemonic)
const seedHex = bip39.mnemonicToSeedHex(mnemonic, password)
const hdNode = qtum.HDNode.fromSeedHex(seedHex, network)
const account = hdNode.deriveHardened(88).deriveHardened(0).deriveHardened(0)
const keyPair1 = account.keyPair

var privatekey = keyPair1.toWIF()
console.log("私钥:"+privatekey)
var address = keyPair1.getAddress()
console.log("地址:"+address)
printInfo(address)

async function printInfo(address) {
    const info = await getInfo(address)
    balance = info.balance + unit
    unconfirmedBalance = info.unconfirmedBalance + unit
    console.log('余额:' + balance)
    console.log('未确认金额:' + unconfirmedBalance)
}

async function getInfo(address) {
    return await _get(`/addr/${address}`)
}

async function _get(url){
  return (await axios.get(apiPrefix + url)).data
}

由于时间限制我未能亲自跑所有的流程

你可能感兴趣的:(qtum 链接入)