@delegatexyz/sdk

中文文档
0.6.0发布于 2025/01/25MITTypeScriptESM + CJS近 30 天下载 9534

This is a minimalist frontend implementation of the delegation v1 and v2 registry. Every function has a 1:1 name of the contract ABI.

原始使用文档
文档目录7 节
  1. Installation
  2. Usage
  3. Read Example
  4. Write Example
  5. API
  6. v2
  7. v1

@delegatexyz/sdk · NPM npm (tag) npm bundle size Twitter URL

This is a minimalist frontend implementation of the delegation v1 and v2 registry. Every function has a 1:1 name of the contract ABI.

Read more about the delegate.xyz via our documentation

Installation

npm install @delegatexyz/sdk viem

Usage

The v1 or v2 SDK require the same parameters:

  • transport: a valid viem Transport.
  • chain: chain from viem/chains (or define your own)
  • isZkSync (optional): boolean to indicate if the chain is zkSync (v2 only, defaults to false)
  • account (optional): A wallet client

account is only required to use the write functions.

Read Example

import { http } from 'viem';
import { DelegateV1, DelegateV2 } from '@delegatexyz/sdk';

const RPC_URL = 'https://ethereum-rpc.publicnode.com';
const v1 = new DelegateV1(http(RPC_URL));
const v2 = new DelegateV2({ userTransport: http(RPC_URL) });

console.log(
  await v1.checkDelegateForAll(
    '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
    '0x70997970C51812dc3A010C7d01b50e0d17dc79C8',
  ),
);

console.log(
  await v2.checkDelegateForAll(
    '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
    '0x70997970C51812dc3A010C7d01b50e0d17dc79C8',
  ),
);

Write Example

To write transactions, you'll need to pass a wallet client.

import { http } from 'viem';
import { mainnet } from 'viem/chains';
import { DelegateV1, DelegateV2 } from '@delegatexyz/sdk';

const account = createWalletClient({
  chain: mainnet,
  transport: custom(window.ethereum),
});

const RPC_URL = 'https://ethereum-rpc.publicnode.com';
const v1 = new DelegateV1(http(), mainnet, account);
const v2 = new DelegateV2({ userTransport: http(RPC_URL), chain: mainnet, account });

console.log(
  await v1.delegateForAll('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0x70997970C51812dc3A010C7d01b50e0d17dc79C8'),
);

console.log(
  await v2.delegateAll(
    '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
    '0x70997970C51812dc3A010C7d01b50e0d17dc79C8',
    true,
  ),
);

API

v2

View Functions

  • checkDelegateForAll(to, from, rights)
  • checkDelegateForContract(to, from, contract, rights)
  • checkDelegateForERC1155(to, from, contract, tokenId, rights)
  • checkDelegateForERC20(to, from, contract, rights)
  • checkDelegateForERC721(to, from, contract, tokenId, rights)
  • getIncomingDelegations(to)
  • getOutgoingDelegations(from)

Write Functions

  • delegateAll(to, right, enable)
  • delegateContract(to, contract, rights, enable)
  • delegateERC1155(to, contract, tokenId, rights, amount)
  • delegateERC20(to, contract, rights, enable)
  • delegateERC721(to, contract, tokenId, rights, enable)
  • multicall(calls)

Raw Functions

These function calls will return back the encoded function data.

  • rawDelegateAll(to, right, enable)
  • rawDelegateContract(to, contract, rights, enable)
  • rawDelegateERC1155(to, contract, tokenId, rights, amount)
  • rawDelegateERC20(to, contract, rights, enable)
  • rawDelegateERC721(to, contract, tokenId, rights, enable)
  • rawMulticall(calls)

v1

View Functions

  • checkDelegateForAll(delegate, vault)
  • checkDelegateForContract(delegate, vault, contract)
  • checkDelegateForToken(delegate, vault, contract, tokenId)
  • getContractLevelDelegations(vault)
  • getDelegatesForAll(vault)
  • getDelegatesForContract(vault, contract)
  • getDelegatesForToken(vault, contract, tokenId)
  • getDelegationsByDelegate(delegate)
  • getTokenLevelDelegations(vault)

Write Functions

  • delegateForAll(delegate, value)
  • delegateForContract(delegate, contract, value)
  • delegateForToken(delegate, contract, tokenId, value)
  • revokeAllDelegates()
  • revokeDelegate(delegate)
  • revokeSelf(vault)

Raw Functions

These function calls will return back the encoded function data.

  • rawDelegateForAll(delegate, value)
  • rawDelegateForContract(delegate, contract, value)
  • rawDelegateForToken(delegate, contract, tokenId, value)
  • rawRevokeAllDelegates()
  • rawRevokeDelegate(delegate)

版本与发布记录

@delegatexyz/sdk 共发布 4 个版本,首次发布于 2023/09/26;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.6.0latest2025/01/251.8 年前
0.5.22024/04/092 年前
0.5.12023/09/263 年前
0.5.02023/09/263 年前

关于 @delegatexyz/sdk 的常见问题

@delegatexyz/sdk 是什么?

This is a minimalist frontend implementation of the delegation v1 and v2 registry. Every function has a 1:1 name of the contract ABI.

如何安装 @delegatexyz/sdk?

在项目目录运行 npm install @delegatexyz/sdk,或使用 pnpm add / yarn add / bun add。

@delegatexyz/sdk 支持 TypeScript 吗?

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

@delegatexyz/sdk 支持 ESM 还是 CommonJS?

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

@delegatexyz/sdk 可以商用吗?

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

@delegatexyz/sdk 的下载量有多少?

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

@delegatexyz/sdk 还在维护吗?

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