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

@depay/web3-tokens-evm

v10.4.3

Published

JavaScript library providing basic functionalities to interact with web3 tokens.

Downloads

182

Readme

Quickstart

yarn add @depay/web3-tokens

or

npm install --save @depay/web3-tokens
import Token from '@depay/web3-tokens'

let token = new Token({
  blockchain: 'ethereum',
  address: '0xa0bed124a09ac2bd941b10349d8d224fe3c955eb'
});

token.address // '0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb'
await token.decimals() // 18
await token.symbol() // 'DEPAY'
await token.name() // 'DePay'

Support

This library supports the following blockchains:

Platform specific packaging

In case you want to use and package only specific platforms, use platform-specific packages:

EVM specific packaging

import Token from '@depay/web3-tokens-evm'

SOLANA specific packaging

import Token from '@depay/web3-tokens-solana'

Functionalities

initalize (new)

import Token from '@depay/web3-tokens'

let token = new Token({
  blockchain: 'ethereum',
  address: '0xa0bed124a09ac2bd941b10349d8d224fe3c955eb'
});

decimals

Retrieves token decimals

await token.decimals() // 18

symbol

Retrieves token symbol

await token.symbol() // DEPAY

name

Retrieves token name

await token.name() // DePay

name for NFT by id

Retrieves token name for token address by NFT id:

await token.name({ id: '42745998150656004690816543961586238000273307462307754421658803578179357246440' }) // NFT Butler Lifetime License

balance

Provides the balance (BigNumber) of the given account:

await token.balance('0xb0252f13850a4823706607524de0b146820F2240') // BigNumber {_hex: "0x0b896d5e9eeaabf4f1", _isBigNumber: true}

this also works for the native token of the given blockchain:

let token = new Token({ ..., address: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE' })
await token.balance('0xb0252f13850a4823706607524de0b146820F2240') // BigNumber {_hex: "0x0b896d5e9eeaabf4f1", _isBigNumber: true}

balance for NFTs (by id)

If you pass a second parameter, it will be used to get the balance for the given account for the given token id:

await token.balance('0xb0252f13850a4823706607524de0b146820F2240', '42745998150656004690816543961586238000273307462307754421658803578179357246440')

BigNumber

Provides the BigNumber amount for a given token (based on the tokens decimals) based on a human readable amount:

let token = new Token({
  blockchain: 'ethereum',
  address: '0xa0bed124a09ac2bd941b10349d8d224fe3c955eb'
}) 

await token.BigNumber(1) // BigNumber '1000000000000000000'
await Token.BigNumber({
  amount: 1,
  blockchain: 'ethereum',
  address: '0xa0bed124a09ac2bd941b10349d8d224fe3c955eb'
}) // BigNumber '1000000000000000000'

readable

Provides a human readable amount based on a given BigInt number.

  • Ending zeros will be eliminated 1.30000 -> 1.3

  • Decimals are dropped if there are none 1.00000 -> 1

await Token.readable({
  amount: '1231211111210000000',
  blockchain: 'ethereum',
  address: '0xa0bed124a09ac2bd941b10349d8d224fe3c955eb'
}) // "1.23121111121"
let token = new Token({
  blockchain: 'ethereum',
  address: '0xa0bed124a09ac2bd941b10349d8d224fe3c955eb'
})

await token.readable('1231211111210000000') // "1.23121111121"

Token Standards

EVM: Token Standards

import Token from '@depay/web3-tokens'

Token.ethereum['20'] // [...] <XYZ>20 standard
Token.bsc['20'] // [...] <XYZ>20 standard

Token.ethereum.ERC20 // [...] ERC20 ABI
Token.bsc.BEP20 // [...] BEP20 ABI

Token.ethereum.WRAPPED // [...] WETH ABI
Token.bsc.WRAPPED // [...] WETH ABI

DEFAULT references the broad default token standard on the respective blockchain:

import Token from '@depay/web3-tokens'

Token.ethereum.DEFAULT // ERC20
Token.bsc.DEFAULT // BEP20

Token[blockchain].DEFAULT

Solana: Token Standards, Constants, Layouts and helper methods

import Token from '@depay/web3-tokens'

Token.solana
// MINT_LAYOUT,
// METADATA_LAYOUT,
// TRANSFER_LAYOUT,
// METADATA_ACCOUNT,
// TOKEN_PROGRAM,
// ASSOCIATED_TOKEN_PROGRAM,
// findProgramAddress({ token, owner })
// findAccount({ token, owner })
// async createTransferInstruction({ token, amount, from, to })
// async createAssociatedTokenAccountInstruction({ token, owner, payer })
// initializeAccountInstruction({ account, token, owner })
// closeAccountInstruction({ account, owner })
// getMetaData
// getMetaDataPDA

Development

Get started

yarn install
yarn dev

Release

npm publish