连接地址-js
Conflux地址的简单编码和解码器.
检查 CIP-37 (中文(简体) ) 对协议.
安装
$ npm install @conflux-dev/conflux-address-js
绩效选择
要获得地址转换性能提升, 您可以安装 @conflux-dev/conflux-address-rust 在你的项目。 用来替换纯正的版本,并获得 10-100 表现提升.
$ npm install --save-optional @conflux-dev/conflux-address-rust
使用量
编码
const confluxAddr = require('@conflux-dev/conflux-address-js')
const hexBuffer = Buffer.from('106d49f8505410eb4e671d51f7d96d2c87807b09', 'hex')
const netId = 1029 // Conflux main-net
console.log(confluxAddr.encode(hexBuffer, netId))
// cfx:aajg4wt2mbmbb44sp6szd783ry0jtad5bea80xdy7p
console.log(confluxAddr.encode(hexBuffer, netId, true)) // verbose mode to generate address with type
// CFX:TYPE.USER:AAJG4WT2MBMBB44SP6SZD783RY0JTAD5BEA80XDY7P
解码
const confluxAddr = require('@conflux-dev/conflux-address-js')
console.log(confluxAddr.decode('cfx:aajg4wt2mbmbb44sp6szd783ry0jtad5bea80xdy7p'))
/*
{ hexAddress:
<Buffer 10 6d 49 f8 50 54 10 eb 4e 67 1d 51 f7 d9 6d 2c 87 80 7b 09>,
netId: 1029,
type: 'user' }
*/
console.log(confluxAddr.decode('CFX:TYPE.USER:AAJG4WT2MBMBB44SP6SZD783RY0JTAD5BEA80XDY7P'))
/*
{ hexAddress:
<Buffer 10 6d 49 f8 50 54 10 eb 4e 67 1d 51 f7 d9 6d 2c 87 80 7b 09>,
netId: 1029,
type: 'user' }
*/
API 密码
encode: 低等编码方法decode: 低等解码方法isValidCfxAddress: 返回布尔值,表示地址是否有效verifyCfxAddress: 检查地址是否有效, 如果不是会丢出错误hasNetworkPrefix: 检查字符串是否有网络前缀simplifyCfxAddress: 返回非动词地址shortenCfxAddress: 返回一个缩短的地址isZeroAddress:检查地址是否为零地址isInternalContractAddress: 检查地址是 Conflux 内部合同地址isValidHexAddress: 检查地址是否为有效的十六进制地址isValidCfxHexAddress: 检查地址在哪里是有效的 Conflux 十六进制地址