npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bfmeta/node-sdk

v4.0.7

Published

bfmeta node sdk for js

Downloads

155

Readme

BFMeta-SDK

工具介绍

  • 本工具支持BFMeta链节点端的接口访问。提供BFMeta链的公私钥对、地址及签名生成工具。
  • 交易buffer数据由连接的节点生成,再由本sdk进行签名后发往节点。
  • 建议自行部署节点达到更好的效果。 https://developer.bfmeta.org/download/

Installation - 安装

$ npm install @bfmeta/node-sdk

Requrements - 必要条件

  • npm

  • typescript

Docs & Community - 文档 & 社区

  • 接口文档参考 https://developer.bfmeta.org/336/overview/

Usage - 用法

import { BFMetaSDK, REQUEST_PROTOCOL} from "@bfmeta/node-sdk";

// 也可以再运行目录下建 config/config.json 填入以下内容,new 的时候就不用传参

const config: BFMetaNodeSDK.ApiConfig = {
    node: {
        /**节点 ip, 默认值 [127.0.0.1] */
        ip: "127.0.0.1",
        /**节点端口号, 默认值 9003 */
        port: 9003,
    },
    //  "请求超时时间, 单位 ms, 默认 10000",
    requestTimeOut: 10000,
    // "请求协议, http || websocket, 默认值 websocket",
    requestProtocol: REQUEST_PROTOCOL.WEBSOCKET,
};

// 这里根据本地环境去实现,可参考以下
import { CryptoHelper } from "@bfmeta/node-sdk/build/test/helpers/cryptoHelper";
const cryptoHelper = new CryptoHelper();
import { FecthDemo } from "@bfmeta/node-sdk/build/test/helpers/FecthDemo";
const fecthDemo = new FecthDemo();
const bfmetaSDK = new BFMetaSDK(config, { netType: "testnet", cryptoHelper }, fecthDemo);

 // 根据助记词生成公私钥对
let keypair = await bfmetaSDK.bfchainSignUtil.createKeypair("your secret");

// 这是该账户的地址
const address = await bfmetaSDK.bfchainSignUtil.getAddressFromPublicKey(keypair.publicKey);
// 这是该账户的公钥(string)
const publicKey = keypair.publicKey.toString("hex");
// 获取节点最新高度
const lastblockResult = await bfmetaSDK.api.basic.getLastBlock();
// 根据条件获取区块
const blockResult = await bfmetaSDK.api.basic.getBlock({});
// 根据条件获取交易
const transactionResult = await bfmetaSDK.api.basic.getTransactions({});

const createResult = await bfmetaSDK.api.transaction.createTransferAsset({
    // 转账金额 1 代表最小单位。100000000 = 1 BFMTEST
    amount: "100000000000",
    // 转移的资产类型,可为空,默认为当前链的主权益
    assetType: "BFMTEST",
    // 接收地址
    recipientId: address,
    // 发起地址的公钥
    publicKey,
    // 手续费
    fee: "2000",
    // 发起高度,需要根据连接节点的高度设置。节点只能处理合法高度内的交易
    applyBlockHeight: 1,
    // 失效高度,同发起高度一起使用。 若发起高度为1000,失效高度为10.那么这笔交易只能在 1000~1010的高度内被确认。这两个字段能够约束本笔交易的有效高度区间。此字段的最大值为创世块内共识决定。
    numberOfEffectiveBlocks: 10
});
if (!createResult.success) {
    throw createResult;
}
const buffer = createResult.result.buffer;
const bytes = Buffer.from(buffer, "base64");
// 生成签名
const signature = (await bfmetaSDK.bfchainSignUtil.detachedSign(bytes, keypair.secretKey)).toString("hex");
// 广播交易
const broadcastResult = await bfmetaSDK.api.transaction.broadcastTransferAsset({
    buffer,
    signature,
});
if (!broadcastResult.success) {
    throw broadcastResult;
}
// 将返回交易体,交易体的格式见实际返回类型。
console.log(broadcastResult);
// 广播交易到节点成功

Changelog - 更新日志

  • 3.0.21
    • 优化节点连接池
  • 3.0.14
    • 修改初始化格式,http模块由外部传入
  • 3.0.13
    • 完善 README 使用说明
  • 3.0.7
    • 完善 multiNodes 参数的使用
  • 3.0.6
    • 新增支持升级服务的接口
  • 3.0.5
    • 修改初始化时传入节点的参数格式
  • 3.0.4
    • 添加 setSignUtil 函数
  • 3.0.2
    • sdk 初始化参数调整
  • 3.0.1
    • sdk中提供了 bfchainSignUtil 工具
  • 3.0.0
    • 重构了本sdk。

License- 许可

本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。