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

uranus-web3

v1.0.9

Published

Uranus JavaScript API

Downloads

13

Readme

uranus-web3.js

Uranus JavaScript API

安装及引用:

npm i uranus-web3 -S

import * as uranus from 'uranus-web3';

demo1:设置节点信息

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

import * as uranus from 'uranus-web3';

console.log(nodeInfo);
web3.utils.default.setEndpoint(nodeInfo); // 设置节点rpc信息

demo2:签名及验证交易

签名交易,返回签名数据

import * as uranus from 'uranus-web3';

const tx = {}
tx.type = 0
tx.nonce = 1
tx.gasPrice = 10000
tx.tos = [
  '0xC08B5542D177ac6686946920409741463a15dDdB',
  '0x970e8128ab834e8eac17ab8e3812f010678cf791'
]
tx.gasLimit = 1000
tx.value = 10000
tx.payload = Buffer.from('sign tx test')

const priv =
  '0x9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658'

var sig = uranus.singer.signTransaction(tx, priv)

console.log('sig ', sig)

验证签名交易,返回地址(交易的发送方)

import * as uranus from 'uranus-web3';

const tx = {}
tx.type = 0
tx.nonce = 1
tx.gasPrice = 10000
tx.tos = [
  '0xC08B5542D177ac6686946920409741463a15dDdB',
  '0x970e8128ab834e8eac17ab8e3812f010678cf791'
]
tx.gasLimit = 1000
tx.value = 10000
tx.payload = Buffer.from('sign tx test')

const signature =
  '0x20ceb32d94ea10f50425233e5d355fa05337d23b50646839c6d0689acdd054557f867ab7e187863a6841efbc19d03ba38762fe24d49815185d5a3f4a7b196ac101'

var addr = uranus.singer.recoverSignedTransaction(tx, signature)


console.log('addr ', addr)

demo3:rlp交易的序列化

import * as uranus from 'uranus-web3';


const tx = {};
tx.type = 0;
tx.nonce = 1;
tx.gasPrice = 10000;
tx.tos = ['0xC08B5542D177ac6686946920409741463a15dDdB', '0x970e8128ab834e8eac17ab8e3812f010678cf791'];
tx.gasLimit = 1000;
tx.value = 10000;
tx.payload = Buffer.from('sign tx test');
signature = uranus.utils.default.hex2Bytes(
   sig
);

var txBytes = uranus.utils.default.ethUtil.rlp.encode([
    tx.type,
    tx.nonce,
    tx.gasPrice,
    tx.tos,
    tx.gasLimit,
    tx.value,
    tx.payload,
    signature
]);

console.log('txBytes ', txBytes.toString('hex'));

demo4:发送交易

发送交易,首先先将交易进行签名(demo1),

demo5: erc20 transfer payload 构建 erc20 转账交易 payload,第一个参数是接收方,第二个是转账金额.

let payload = '0x';
payload += uranus.utils.default.getContractPayload(
    'transfer',
    ['address', 'uint256'],
    ['0x3f5ce5fbfe3e9af3971dd833d26ba9b5c936f0be', '41400000000000000000']
);