是否可以使用web3.jslibary进行base58编码和解码?
web3.js似乎包含了大数库,但我不确定它是否能够处理C1所使用的base58编码。
我希望有一个函数看起来有点像这样(失败):例如(基于这)
web3.utils.toBN('QmXGTaGWTT1uUtfSb2sBAvArMEVLK4rQEcQg5bv7wwdzwU', 58) //web3 v1.x或
web3.toBigNumber("QmXGTaGWTT1uUtfSb2sBAvArMEVLK4rQEcQg5bv7wwdzwU",58) //web3 v0.x它从base58数返回一个大数整数。Is可以使用web3.js库进行base58编码和解码?
发布于 2018-07-12 07:17:54
‘s不提供base58编解码器,因为它只涉及到ethereum的接口,所以没有直接使用这个特性。您必须使用像bs58这样的模块。
下面是一个例子:
const bs58 = require('bs58')
const BN = require('bn.js')
const hash = 'QmXGTaGWTT1uUtfSb2sBAvArMEVLK4rQEcQg5bv7wwdzwU'
const hex = bs58.decode(hash).toString('hex')
console.log(hex) // 122084a644bfcb8639e1b1a1fc72fd0ad1826b91f7a9baa06ad409ac3c02b31f981b
const n = new BN(hex, 16)
console.log(n.toString(10)) // 537335293128262426148241029128274019001757729355677528305490323656269309818148891https://ethereum.stackexchange.com/questions/44298
复制相似问题