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

oex-web3-ts

v1.2.4

Published

Oexchain Web3 TS API

Downloads

2

Readme

安装及引用:

npm i oex-web3-ts -S

import * as oex from 'oex-web3-ts';

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

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

    rpc 文档:https://github.com/oexplatform/oexchain/wiki/JSON-RPC

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

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

import * as oex from 'oex-web3-ts';

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

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

demo2: 发送多签名交易

import * as oex from 'oex-web3-ts';

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

demo3: 发送单签名交易

import * as oex from 'oex-web3-ts';

txInfo = {...}
signInfo1 = await oex.oex.signTx(txInfo, privateKey1, 0);
oex.oex.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 oex from 'oex-web3-ts';

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

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