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

@habsyr/erc20-token

v0.3.0-beta.1

Published

_Inspired by the since-depreciated [`ERC20TokenWrapper`](https://github.com/0xProject/0x-monorepo/blob/b43c9f075cca28fceef937eae47ea02547707239/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts) from @0xProject._

Downloads

3

Readme

ERC20 Token (erc20-token)

Inspired by the since-depreciated ERC20TokenWrapper from @0xProject.

Exports ERC20Token, a helper class for working with multiple ERC-20 tokens without having to instantiate a new wrapper for each token.

Instances of ERC20Token include helper methods for interacting with the 0x ERC-20 AssetProxy contract to get and set ERC-20 proxy allowances for trading in the 0x ecosystem.

Source maps and type declaration are files included in published builds.

View the documentation here.

Usage

Use the ERC20Token class to perform any action on an underlying ERC-20 contract via simple JavaScript (TypeScript) abstractions.

Install

Add to your project:

# with yarn
yarn add @habsyr/erc20-token

# with npm
npm i --save @habsyr/erc20-token

Import

See src/index.ts for all available exports.

TypeScript/ES6+ (recommended):

import { ERC20Token, BigNumber, MAX_ALLOWANCE } from "@habsyr/erc20-token";

CommonJS:

const { ERC20Token, BigNumber, MAX_ALLOWANCE } = require("@habsyr/erc20-token");

Initialize

Instantiate a new ERC20Token instance with a supported Ethereum provider. Usage of web3 is shown below, but any standard provider will work.

import { ERC20Token } from "@habsyr/erc20-token";
import Web3 from "web3";

const web3 = new Web3("http://localhost:8545");
const erc20 = new ERC20Token(web3.currentProvider);

Interact

Use erc20 instances (see above) to perform on-chain transactions, view balances, etc.

All methods accept the ERC-20 token's address as the first parameter. Under the hood, it maintains a cache of address => wrapper contract so the first time you call a method for a given token, it will be slightly slower than subsequent calls.

Be sure to see the documentation for all available methods.

// Made up user addresses
const MY_ADDRESS = "0x0a66b68a0d22d4d5c22012ec3b9855a7d7194019";
const YOUR_ADDRESS = "0x39755356759ce0d7f32dc8dc45414bca409ae24e";

// Mainnet DAI stablecoin (v1) address
const DAI_ADDRESS = "0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359";

// Get a balance
const balance = await erc20.getBalanceAsync(DAI_ADDRESS, MY_ADDRESS);

// Check a spender allowance
const allowance = await erc20.getAllowanceAsync(DAI_ADDRESS, MY_ADDRESS, YOUR_ADDRESS);

// Set an unlimited ERC-20 proxy allowance (for 0x trading)
const txId = await erc20.setUnlimitedProxyAllowanceAsync(DAI_ADDRESS);

// Transfer some tokens (after converting to token base units - 18 decimals for DAI)
const amount = new BigNumber(10).times("1e18");
const txId = await erc20.transferAsync(
    DAI_ADDRESS,
    YOUR_ADDRESS,
    amount,
    {
        from: MY_ADDRESS,
    },
);

View the docs/ folder for more documentation.

Develop

Instructions for working with hrharder/erc20-token (contributions welcome).

Build

Compile the TypeScript source, and generate artifacts (source maps, declaration files):

yarn build

Documentation

Re-generate documentation:

yarn docs

Test

Start a 0x ganache snapshot RPC server and run tests (requires docker):

yarn test

Run tests with a custom RPC (CI, etc.):

WEB3_URL=http://localhost:8545 yarn test:ci

License

Originally written by Henry Harder (c) 2019.

Licensed under an MIT license.

Contributing

All contributions welcome, subject to review and sanity checks (is this helpful, etc.)

Feel free to open an issue or PR as needed.