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

fractal-web3

v1.1.23

Published

Fractal Web3 JS API

Downloads

26

Readme

安装及引用:

npm i fractal-web3 -S

import * as fractal from 'fractal-web3'; 

根据rpc功能划分了不同的域:

  • fractal.account.*: 包括查看账户、资产等功能
  • fractal.dpos.*: 包括查看竞选、出块节点信息以及dpos共识相关信息等功能
  • fractal.ft.*: 包括查看区块、交易信息以及签名、发送交易等功能
  • fractal.fee.*: 包括查看不同账户手续费的功能
  • fractal.miner.*: 包括启动挖矿、停止挖矿、设置coinbase等功能
  • fractal.p2p.*: 包括增加、删除节点等功能
  • fractal.txpool.*: 包括获取txpool信息以及设置gas price等功能
  • fractal.utils.*: 包括rlp编码、合约payload编码等功能

rpc文档:https://github.com/fractalplatform/fractal/wiki/JSON-RPC

demo1:设置节点信息、查看账户信息

节点rpc默认是htp://127.0.0.1:8545,如不是,必须先设置好节点信息,才可进行后续操作

import * as fractal from 'fractal-web3';

const nodeInfo = 'htp://127.0.0.1:8545';  
fractal.utils.setProvider(nodeInfo);  //设置节点rpc信息

try {
  const accountInfo = await fractal.account.getAccountByName('fractal.admin');
  ...
} catch (error) {
  console(error);  
}

demo2: 发送多签名交易

import * as fractal from 'fractal-web3';

// 交易完整结构体:{chainId, gasAssetId, gasPrice, actions:[{actionType, accountName, nonce, gasLimit, toAccountName, assetId, amount, payload, remark}]}
// 其中chainId, gasAssetId, nonce, payload 以及 remark这几个参数如果不传,sdk会根据实际情况自动填充
txInfo = {...}
signInfo1 = await fractal.ft.signTx(txInfo, privateKey1);  //获取第一个签名
signInfo2 = await fractal.ft.signTx(txInfo, privateKey2);  //获取第二个签名
multiSignInfos = [{signInfo1, [0]}, {signInfo2, [1]}];
parentIndex = 0; // 签名级别,如果为0,表示是自己账号签名,如果为1,表示父账号签名,如果为2,表示父父账号签名
fractal.ft.sendSeniorSigTransaction(txInfo, multiSignInfos, 0).then(txHash => {...}).catch(error => {...});  // 发送多签名交易

demo3: 发送单签名交易

import * as fractal from 'fractal-web3';

txInfo = {...}
signInfo1 = await fractal.ft.signTx(txInfo, privateKey1, 0);
fractal.ft.sendSingleSigTransaction(txInfo, signInfo1).then(txHash => {...}).catch(error => {...});

demo4: 合约方法调用

  • 合约代码:
contract hello {
    string greeting;
    
    function hello(string _greeting) public {
        greeting = _greeting;
    }

    function say() constant public returns (string) {
        return greeting;
    }
}
  • sdk调用方式
import * as fractal from 'fractal-web3';

// 调用合约的hello方法
const payload = fractal.utils.getContractPayload('hello', ['string'], ['fractal blockchain']); //payload会填入txInfo中
const txInfo = {...}  // 构造合约交易对象
signInfo1 = await fractal.ft.signTx(txInfo, privateKey1);
fractal.ft.sendSingleSigTransaction(txInfo, signInfo1, 0).then(txHash => {...}).catch(error => {...});

// 调用合约的say方法,由于say是一个constant类型的方法,只需要从链上读取数据,因此不需要发送交易,只要调用rpc中的call方法即可获得结果
const payload = fractal.utils.getContractPayload('say', [], []);
const callInfo = {actionType:0, from:'youraccount', to: 'contractAccountName', assetId:0, gas:100000, gasPrice:10, value:100, data:payload, remark:''};
fractal.ft.call(callInfo, 'latest').then(result=>{...});