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

@adraffy/eth-tools

v0.0.10

Published

Compact set of ES6 tools for Ethereum dapps that work in the browser

Downloads

13

Readme

eth-tools.js

Compact set of ES6 tools for Ethereum dapps that work in the browser.

import * as tools from '@adraffy/eth-tools';
// browser:
// 'https://unpkg.com/@adraffy/eth-tools@latest/dist/eth-tools.min.js'

Providers

let provider = new WebSocketProvider({url: 'ws://...', /*WebSocket*/}); 
// pass it a WebSocket implementation for nodejs

let provider = new FetchProvider({url: 'https://cloudflare-eth.com', /*fetch*/}); 
// pass it a fetch implementation for nodejs

// create a provider set
let providers = new Providers();
// add providers with fixed chain id
providers.add_static(1, provider) // mainnet
providers.add_static(137, new FetchProvider({url: 'https://rpc-mainnet.matic.network'})); // matic
// allow for shitty startup
determine_window_provider.then(p => {
	// add providers with dynamic chain id (eg. metamask)
	// this also fixes "header not found" bug
	providers.add_dynamic(p);
}).catch(() => {}); // ignore error

// create a provider set with a preferred chain
let view = providers.view(1); // chain id
// get the default provider
await view.get_provider();
// find a provider for a chain
await view.find_provider(2);

ENS

import {ens_normalize} from '@adraffy/ens-normalize.js'; // recommended

// use a single provider for whatever chain it corresponds to
// use ens_normalize() as the normalizer, string -> string
let ens = new ENS({provider, ens_normalize}); 

// use a provider set, but operate on mainnet
// this is useful for resolving cross-chain avatars
let ens = new ENS({provider: providers.view(1), ens_normalize});

// resolve a name or an address
// throw before returning ENSName object
await ens.resolve('bRAntly.eth');
// resolve name and return an ENSName or throw
let name = await ens.resolve('bRAntly.eth');
console.log(name.node); 
// Uint256 (namehash)
console.log(name.resolver); 
// resolver contract address (or undefined)
console.log(name.is_input_normalized());
// false
console.log(name.is_equivalent_name('BRANTLY.ETH'));
// true
console.log(await name.get_address());
// "0x983110309620D911731Ac0932219af06091b6744"
console.log(await name.get_primary());
// "brantly.eth"
console.log(await name.is_owner_primary_name());
// true
console.log(await name.is_input_display());
// false
console.log(await name.get_content());
// {hash: Uint8Array, url: ...}
console.log(await name.get_text('com.twitter'));
// "brantlymillegan"
console.log(await name.get_addr(['BTC', 'XCH']));
// {"BTC": ..., "XCH": ...}
console.log(await name.get_pubkey());
// {x: Uint256, y: Uint256}
console.log(await ens.is_dot_eth_available('brantly'));
// false
console.log(await ens.get_dot_eth_owner('brantly'));
// "0x983110309620D911731Ac0932219af06091b6744"
console.log((await ens.primary_from_address('0x983110309620D911731Ac0932219af06091b6744'));
console.log((await ens.owner('0x983110309620D911731Ac0932219af06091b6744').resolve()).name);
// "brantly.eth"

NFT

let nft = new NFT(provider, '0xdc8bed466ee117ebff8ee84896d6acd42170d4bb');
console.log(await nft.get_type()); // ERC-721
console.log(await nft.get_token_uri(1)); // ifps://...

ABI

let enc = ABIEncoder.method('func(string,bytes32'); // or hashed signature
enc.string('hello');
enc.number(1234);
enc.number(Uint256.from_number(1234));
enc.addr('0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41');
console.log(enc.build());     // Uint8Array
console.log(enc.build_hex()); // hex-string (0x-prefixed)

let dec = ABIDecoder.from_hex(enc.build_hex());
dec.read_bytes(4); // skip signature
console.log(dec.string());  // read a string
console.log(dec.number());  // read u256 as number, throws if too big
console.log(dec.uint256()); // read u256
console.log(dec.addr());    // read 40-char hex-string (0x-prefixed w/checksum)

Address and Utils

let a = '0xb8c2c29ee19d8307cb7255e1cd9cbde883a267d5';
let b = checksum_address(a);
console.log(b); 
// "0xb8c2C29ee19D8307cb7255e1Cd9CbDE883A267d5"
console.log(a.toLowerCase() === b.toLowerCase());
// true
console.log([is_valid_address(a), is_checksum_address(b)]);
// [true, true]
console.log([is_checksum_address(a), is_checksum_address(b)]);
// [false, true]