@depay/web3-tokens

中文文档
11.1.0发布于 2025/04/17MITESM + CJS零依赖近 30 天下载 3669

JavaScript library providing basic functionalities to interact with web3 tokens.

原始使用文档
文档目录18 节
  1. Quickstart
  2. Support
  3. Platform specific packaging
  4. EVM (Ethereum Virtual Machine) specific packaging
  5. SVM (Solana Virtual Machine) specific packaging
  6. Functionalities
  7. initalize (new)
  8. decimals
  9. symbol
  10. name
  11. name for NFT by id
  12. balance
  13. BigNumber
  14. readable
  15. Token Standards
  16. Development
  17. Get started
  18. Release

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 (Ethereum Virtual Machine) specific packaging

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

SVM (Solana Virtual Machine) 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

版本与发布记录

@depay/web3-tokens 共发布 59 个版本,首次发布于 2021/11/26;过去 12 个月发布了 0 个版本。

版本发布日期距今
11.1.0latest2025/04/171.6 年前
11.0.02025/03/161.7 年前
10.4.42024/12/271.9 年前
10.4.32024/09/272 年前
10.4.12024/09/122 年前
10.4.02024/09/122 年前

关于 @depay/web3-tokens 的常见问题

@depay/web3-tokens 是什么?

JavaScript library providing basic functionalities to interact with web3 tokens.

如何安装 @depay/web3-tokens?

在项目目录运行 npm install @depay/web3-tokens,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@depay/solana-web3.js(^1.98.0)、@depay/web3-blockchains(^9.7.9)、@depay/web3-client(^11.0.1)、ethers(^5.7.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@depay/web3-tokens 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/depay__web3-tokens 是否存在。

@depay/web3-tokens 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@depay/web3-tokens 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@depay/web3-tokens 可以商用吗?

@depay/web3-tokens 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@depay/web3-tokens 的下载量有多少?

根据 npm 官方下载统计,@depay/web3-tokens 在 2026/10/12 – 2026/11/10 这 30 天内被下载 3,669 次,日均约 122 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@depay/web3-tokens 还在维护吗?

最新版本 11.1.0 发布于 2025/04/17(1.6 年前);至今共发布 59 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/11/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。