@depay/web3-payments

中文文档
15.3.3发布于 2025/09/18MITESM + CJS零依赖近 30 天下载 4018

JavaScript library to scan crypto wallets for liquefiable assets and perform cost-effective, auto-converted payments on-chain.

原始使用文档
文档目录22 节
  1. Quickstart
  2. Support
  3. Platform specific packaging
  4. EVM (Ethereum Virtual Machine) platform specific packaging
  5. SVM (Solana Virtual Machine) platform specific packaging
  6. Functionalities
  7. route
  8. routers
  9. plugins
  10. Domain Knowledge
  11. Payment Routing Priorities
  12. Data Structures
  13. PaymentRoute
  14. Development
  15. Get started
  16. Web3 Payments
  17. Chain Agnostic (Multichain)
  18. Permissionless
  19. Trustless
  20. Easy to use
  21. Open Source
  22. Multichain

Quickstart

yarn add @depay/web3-payments

or

npm install --save @depay/web3-payments

Make sure you install all required dependencies too:

yarn add @depay/web3-constants @depay/web3-exchanges @depay/web3-tokens ethers decimal.js

or if you use npm

npm i @depay/web3-constants @depay/web3-exchanges @depay/web3-tokens ethers decimal.js
import { route } from '@depay/web3-payments'

let paymentRoutes = await route({
  accept: [
    {
      blockchain: 'ethereum',
      token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
      amount: 20,
      receiver: '0xb0252f13850a4823706607524de0b146820F2240'
    },{
      blockchain: 'solana',
      token: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
      amount: 20,
      receiver: '3Hrw6AsNyJAp71Nkgo4tzJwvGM47DzqMdAtf8ojptkXk'
    }
  ],
  from: {
    ethereum: '0x317D875cA3B9f8d14f960486C0d1D1913be74e90',
    solana: '2UgCJaHU5y8NC4uWQcZYeV9a5RyYLF7iKYCybCsdFFD1'
  }
})

Support

This library supports the following blockchains:

Platform specific packaging

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

EVM (Ethereum Virtual Machine) platform specific packaging

import { route } from '@depay/web3-payments-evm'

Make sure you install all required dependencies for evm specific packaging too:

yarn add @depay/web3-blockchains @depay/web3-exchanges-evm @depay/web3-tokens-evm ethers decimal.js

or if you use npm

npm i @depay/web3-blockchains @depay/web3-exchanges-evm @depay/web3-tokens-evm ethers decimal.js

SVM (Solana Virtual Machine) platform specific packaging

import { route } from '@depay/web3-payments-svm'

Make sure you install all required dependencies for solana specific packaging too:

yarn add @depay/web3-blockchains @depay/web3-exchanges-svm @depay/web3-tokens-svm @depay/solana-web3.js

or if you use npm

npm i @depay/web3-blockchains @depay/web3-exchanges-svm @depay/web3-tokens-svm @depay/solana-web3.js

Functionalities

route

Routes payment and returns payment routes:

import { route } from '@depay/web3-payments'

let paymentRoutes = await route({
  accept: [{
    blockchain: 'ethereum',
    token: '0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb',
    amount: 20,
    receiver: '0xb0252f13850a4823706607524de0b146820F2240'
  }],
  from: {
    ethereum: '0x5Af489c8786A018EC4814194dC8048be1007e390',
  }
})

Also allows to pass in multiple accepted means of payment:

import { route } from '@depay/web3-payments'

let paymentRoutes = await route({
  accept: [
    {
      blockchain: 'ethereum',
      token: '0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb',
      amount: 20,
      receiver: '0xb0252f13850a4823706607524de0b146820F2240'
    },{
      blockchain: 'bsc',
      token: '0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb',
      amount: 20,
      receiver: '0xb0252f13850a4823706607524de0b146820F2240'
    }
  ],
  from: {
    ethereum: '0x5Af489c8786A018EC4814194dC8048be1007e390',
    bsc: '0x5Af489c8786A018EC4814194dC8048be1007e390'
  }
})

drip routes

If you want to work with intermediate routing results over waiting for all routes to be calculated, you can use the the drip option which will drip every single route individually:

import { route } from '@depay/web3-payments'

let paymentRoutes = await route({
  drip: (route)=> {
    // yields every single route
  }
})

allow (list)

Allows only fromTokens (from the sender) that are part of the allow list:

let paymentRoutes = await route({

  allow: {
    ethereum: [
      '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', // ETH
      '0xdac17f958d2ee523a2206206994597c13d831ec7', // USDT
      '0x6b175474e89094c44da98b954eedeac495271d0f'  // DAI
    ],
    bsc: [
      '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', // BNB
      '0xe9e7cea3dedca5984780bafc599bd69add087d56', // BUSD
      '0x55d398326f99059ff775485246999027b3197955'  // BSC-USD
    ]
  }
})

deny (list)

Filters fromTokens to not be used for payment routing:

let paymentRoutes = await route({

  deny: {
    ethereum: [
      '0x6b175474e89094c44da98b954eedeac495271d0f'  // DAI
    ],
    bsc: [
      '0x55d398326f99059ff775485246999027b3197955'  // BSC-USD
    ]
  }
})

fee

route allows you to configure a fee that is taken from the payment amount and is sent to another receiver (the fee receiver):

let paymentRoutes = await route({
  
  accept: [{
    //...
    fee: {
      amount: '3%',
      receiver: '0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B'
    }
  }]
})

// splits 3% of the amount paid and sends it to the feeReceiver

You can define up to max. 2 fees and separate fee receivers:

let paymentRoutes = await route({
  
  accept: [{
    //...
    fee: { amount: '3%', receiver: '0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B'},
    fee2: { amount: '1%', receiver: '0x1dCf54C768352d5A5be0F08891262fd0E53A37ce'},
  }]
})

// splits 3% of the amount paid and sends it to the feeReceiver 1: 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B
// splits 1% of the amount paid and sends it to the feeReceiver 2: 0x1dCf54C768352d5A5be0F08891262fd0E53A37ce

fee.amount can be passed as percentage (String with ending %) or as a human readable number/decimal

let paymentRoutes = await route({
  
  accept: [{
    //...
    fee: {
      amount: 0.3,
      receiver: '0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B'
    }
  }]
})
// splits 0.3 of the amount paid and sends it to the feeReceiver

protocolFee

route allows you to configure a protocolFee that is taken from the payment to pay the protocol:

let paymentRoutes = await route({
  
  accept: [{
    //...
    protocolFee: '1.5%'
    
  }]
})

// leaves 1.5% of the outToken to the protocol when payment has been performed

routers

Exports basic router information (address and api):

import { routers } from '@depay/web3-payments'

routers.ethereum.address // 0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92

plugins

Exports plugin addresses:

import { plugins } from '@depay/web3-payments'

plugins.ethereum.payment // 0x99F3F4685a7178F26EB4F4Ca8B75a1724F1577B9

Domain Knowledge

Payment Routing Priorities

  1. If user has a requested token in his wallet, a direct token transfer to the receiver will be prioritized

  2. Any token that can be liquidated on decentralized exchange and has already been approved for the DePay router will be second priority

  3. All other liquefiable tokens that still require token approval will be prioritized last

Data Structures

PaymentRoute

Payment routes are provided in the following structure:

{
  blockchain: String (e.g. ethereum)
  fromAddress: String (e.g. '0xd8da6bf26964af9d7eed9e03e53415d37aa96045')
  fromToken: Token (see @depay/web3-tokens)
  fromAmount: BigNumber (e.g. <BigNumber '31000000000000000000'>)
  fromDecimals: number (e.g. 18)
  fromBalance: BigNumber (e.g. <BigNumber '10000000000000000000'>)
  toToken: Token (see @depay/web3-tokens)
  toAmount: BigNumber (e.g. <BigNumber '21000000000000000000'>)
  toDecimals: number (e.g. 18)
  toAddress: String (e.g. '0x65aBbdEd9B937E38480A50eca85A8E4D2c8350E4')
  fee: Object (e.g. undefined or fee object)
  feeAmount: BigNumber (e.g. <BigNumber '2100000000000000000'>)
  fee2: Object (e.g. undefined or fee object)
  feeAmount2: BigNumber (e.g. <BigNumber '1100000000000000000'>)
  protocolFee: String (e.g. '1.5%')
  protocolFeeAmount: BigNumber (e.g. <BigNumber '2100000000000000000'>)
  exchangeRoutes: Array (list of exchange routes offering to convert )
  currentRouterAllowance: BigNumber (e.g. <BigNumber '2100000000000000000'>)
  currentPermit2Allowance: BigNumber (e.g. <BigNumber '2100000000000000000'>)
  approvalRequired: Boolean (e.g. true)
  getRouterApprovalTransaction: async (options)=> Transaction (see @depay/web3-wallets)
  getPermit2ApprovalTransaction: async (options)=> Transaction (see @depay/web3-wallets)
  getPermit2ApprovalSignature: async ()=> SignatureTransferSignature
  getTransaction: async (options)=> Transaction (see @depay/web3-wallets for details), options can contain { wallet }
}

currentRouterAllowance: Provides the current set allowance for the payment router as BigNumber.

currentPermit2Allowance: Provides the current set allowance for permit2 as BigNumber.

approvalRequired: Payment requires an approval (e.g. token transfers on EVM without any pre-approval).

getRouterApprovalTransaction: Transaction to approve the fromToken being used from the payment router to perform the payment. Setting options to { limited: true } only approves the amount required instead of a max. approval.

getPermit2ApprovalTransaction: Transaction to approve the fromToken being used from the payment router using permit2 to perform the payment.

getPermit2ApprovalSignature: Receive the permit2 signature transfer signature that can be passed to getTransaction({ signature }). Requires prior getPermit2ApprovalTransaction.

See @depay/web3-wallets for details about the transaction format.

Development

Get started

yarn install
yarn dev

Web3 Payments

The future is Web3 Payments.

Blockchains hold the potential to faster, simpler and smarter payments.

Web3 Payments are borderless, peer-to-peer, and support multiple tokens and blockchains.

Accept any asset type that your customers already have in their wallet. DePay is blockchain agnostic and can at any time be extended on any blockchain-specific plugin. Interoperability, scalability & flexibility are the cornerstones of our protocol. Accepting any asset that users already have in their wallets no matter which blockchain these are held on, reduces friction when performing decentralized payments.

Chain Agnostic (Multichain)

Interoperability is the key principle on which our infrastructure is built. DePay is extensible around any blockchain, ensuring a competitive cross-chain future.

Permissionless

Interoperability is the key principle on which our infrastructure is built. DePay is extensible around any blockchain, ensuring a competitive cross-chain future.

Trustless

Most Web3 Payment providers & processors receive payments to wallets that they manage themselves. Only in a further intermediate step are the payments paid out to sellers. DePay does not act as an intermediary. Every intermediate step is replaced by smart contracts which are connected to decentralized liquidity pools. As a result, trust is no longer required.

Easy to use

Our ambition was to create an even easier user experience than you're used to from shopping in current non-crypto e-commerce stores. We think we've done a good job of that.

Open Source

Feel free to use & contribute to our codebase at. We're happy to have you look under our hood. The DePay protocol will always remain open source.

Multichain

DePay calculates payment routes on multiple blockchains simultaneously despite what your wallet is currently connected to. Our software automatically detects & switches the network if required.

版本与发布记录

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

版本发布日期距今
15.3.3latest2025/09/181.1 年前
15.3.22025/07/021.4 年前
15.3.12025/06/281.4 年前
15.3.02025/05/141.5 年前
15.2.12025/05/141.5 年前
15.2.02025/05/141.5 年前

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

@depay/web3-payments 是什么?

JavaScript library to scan crypto wallets for liquefiable assets and perform cost-effective, auto-converted payments on-chain.

如何安装 @depay/web3-payments?

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

@depay/web3-payments 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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

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

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