@delegatexyz/sdk
TypeScript icon, indicating that this package has built-in type declarations

0.5.2 • Public • Published

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:

account is only required to use the write functions.

Read Example

import { http } from "viem"
import { DelegateV1, DelegateV2 } from "delegatecash";

const RPC_URL = "";
const v1 = new DelegateV1(http(RPC_URL))
const v2 = new DelegateV2(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 "delegatecash";

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

const v1 = new DelegateV1(http(), mainnet, account)
const v2 = new DelegateV2(http(), 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)

Readme

Keywords

none

Package Sidebar

Install

npm i @delegatexyz/sdk

Weekly Downloads

1,430

Version

0.5.2

License

MIT

Unpacked Size

193 kB

Total Files

11

Last publish

Collaborators

  • ryeshrimp