@gooddollar/web3sdk-v2

中文文档
0.4.49发布于 2026/11/05MITTypeScriptESM + CJS近 30 天下载 3880

ethers and react hooks based on usedapp sdk for GoodDollar protocol

原始使用文档
文档目录7 节
  1. How to use
  2. Web3Context
  3. Reserve-limit QA mode
  4. emit TX
  5. Hooks
  6. useNetworkSwitch
  7. useMultiCallAtChain

GoodUI Web3Context

A Wrapper around usedapp, providing a context for using web3. All of usedapp is available, plus usefull utilities for:

  • multicall specific chain
  • request top app for network switch
  • emit TXs events

How to use

Web3Context

Supply usedapp config as usuall.

import { Web3Provider, Fuse } from "../contexts/Web3Context";
import { useMulticallAtChain, CallsResult } from './useMulticallAtChain'
import { Mainnet, Call } from "@usedapp/core";
...

<Web3Provider config={{ multicallVersion: 1, networks: [Fuse, Mainnet], readOnlyUrls: { 122: 'https://rpc.fuse.io' } }}>
  <YourAPP />
</Web3Provider>

Reserve-limit QA mode

The shared opt-in API is qa?: { forceTradeLimits?: boolean } on the SDK Web3Provider. ProtocolUI should map REACT_APP_QA_FORCE_TRADE_LIMITS=true to qa={{ forceTradeLimits: true }} only in its development build, and gate the labelled QA flow on useWeb3Context().qa?.forceTradeLimits === true. Missing or false capability means the active SDK does not support this mode.

The SDK additionally requires NODE_ENV === "development"; production builds always report the effective capability as false and do not activate the QA path. This build safeguard is independent of env, which selects contract deployments. Use Celo/XDC mainnet read-only RPC data rather than changing the deployment environment. On Celo/XDC, swapIn/swapOut calls raise the recognized L0Out Exceeded error through the existing classifier without requesting a signer or submitting a transaction. Direct approval and other Reserve submission calls are blocked with a separate QA-disabled error. Balances, allowances, success/receipt states, and live transaction execution are not simulated.

Rebuild and yalc-publish the SDK with yarn workspace @gooddollar/web3sdk-v2 build. This runs ctix and TypeScript builds followed by yalc publish --push --sig; npm publication is not required for the paired QA workflow.

emit TX

Notify listeners about TX your compoent has done Listen to TXs by other components

import { Web3Context, TxDetails } from "../contexts/Web3Context";

const { txEmitter } = useContext(Web3Context)

txEmitter.emit({title: 'test tx',txhash:'0x0', from:'0x1', to:'0x2'}: TxDetails)
txEmitter.on((tx:TxDetails) = > console.log(tx))

Hooks

useNetworkSwitch

If you are using GoodUI components, they need to be able to request a network switch. You can supply that function by calling setSwitchNetwork(() => (chainId) => Promise<Boolean | undefined> with your function. Your app needs to implement the logic for network switching once your funciton is being called. your function should return false if switch did not complete or true if switch was completed.

import { useSwitchNetowrk } from "@gooddollar/web3context";
...
const { switchNetwork, setSwitchNetwork } = useSwitchNetowrk()
const switchit = useCallback(async (id: number) => {
        console.log("setting network:", id)
        return true
},[])
setSwitchNetwork(() => switchit) //this is required, you need to pass a function that returns your functions

If you are building a component, then the component can signal the enclosing app it needs network switch by calling switchNetwork(chainId):Promise<Boolean | undefined>

useMultiCallAtChain

Performs multicall to a specific chain using the rpc defined for that chain in usedapp config readOnlyUrls

import { ERC20Interface } from "@usedapp/core";
import { Contract } from "ethers"
import { useMulticallAtChain, CallsResult } from './useMulticallAtChain'

...
const callMulti = useMulticallAtChain(122)
const [results, setResults] = useState<CallsResult>()
const calls: Call[] = [
  {
      contract: new Contract("0x495d133B938596C9984d462F007B676bDc57eCEC", ERC20Interface),
      method: 'balanceOf',
      args: ['0x66582D24FEaD72555adaC681Cc621caCbB208324']
  },
  {
      contract: new Contract("0x495d133B938596C9984d462F007B676bDc57eCEC", ERC20Interface),
      method: 'totalSupply',
      args: []
  }]

const results = await callMulti(calls)

版本与发布记录

@gooddollar/web3sdk-v2 共发布 457 个版本,首次发布于 2022/06/27;过去 12 个月发布了 16 个版本。

版本发布日期距今
0.4.49latest2026/11/0511 天前
0.4.472026/08/043 个月前
0.4.462026/07/233 个月前
0.4.452026/07/164 个月前
0.4.442026/07/164 个月前
0.4.432026/06/264 个月前

其他发布通道:beta → 0.4.1-beta.04ed25b3。

关于 @gooddollar/web3sdk-v2 的常见问题

@gooddollar/web3sdk-v2 是什么?

ethers and react hooks based on usedapp sdk for GoodDollar protocol

如何安装 @gooddollar/web3sdk-v2?

在项目目录运行 npm install @gooddollar/web3sdk-v2,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:viem(2.*)、react(>=17)、wagmi(2.*)、react-native(*)、@reown/appkit(1.*)、@usedapp/core(*)、react-native-web(*)、@tanstack/react-query(5.*)、@reown/appkit-adapter-wagmi(1.*)、@react-native-async-storage/async-storage(1.17.10)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@gooddollar/web3sdk-v2 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@gooddollar/web3sdk-v2 支持 ESM 还是 CommonJS?

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

@gooddollar/web3sdk-v2 可以商用吗?

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

@gooddollar/web3sdk-v2 的下载量有多少?

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

@gooddollar/web3sdk-v2 还在维护吗?

最新版本 0.4.49 发布于 2026/11/05(11 天前);至今共发布 457 个版本,其中过去 12 个月发布了 16 个;首次发布于 2022/06/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。