API
Guides
Delegates

Manage user delegates

This guide shows how to interact with the Safe Transaction Service API to manage user delegates.

The different steps are implemented using Curl (opens in a new tab) requests, the Safe{Core} SDK (opens in a new tab) TypeScript library and the safe-eth-py (opens in a new tab) Python library.

Prerequisites

  1. Node.js and npm (opens in a new tab) when using the Safe{Core} SDK.
  2. Python (opens in a new tab) >= 3.9 when using safe-eth-py.
  3. Have a Safe account.

Steps

Install dependencies


_10
yarn add ethers @safe-global/api-kit @safe-global/protocol-kit @safe-global/types-kit

Imports


_10
import { ethers } from 'ethers'
_10
import SafeApiKit, { AddSafeDelegateProps } from '@safe-global/api-kit'

Get the delegates from a Safe


_10
// Initialize the API Kit
_10
const apiKit = new SafeApiKit({
_10
chainId: 11155111n
_10
})
_10
_10
// Get the Safe delegates
_10
const delegates = await apiKit.getSafeDelegates({
_10
delegatorAddress: config.SAFE_ADDRESS
_10
})

Add a delegate to a delegator


_17
const provider = new ethers.JsonRpcProvider(config.RPC_URL)
_17
_17
const ownerA = new ethers.Wallet(config.OWNER_A_PRIVATE_KEY, provider)
_17
const ownerAAddress = await ownerA.getAddress()
_17
_17
const ownerB = new ethers.Wallet(config.OWNER_B_PRIVATE_KEY, provider)
_17
const ownerBAddress = await ownerB.getAddress()
_17
_17
const delegateConfig: AddSafeDelegateProps = {
_17
delegateAddress: ownerBAddress || '0x',
_17
delegatorAddress: ownerAAddress || '0x',
_17
signer: ownerA,
_17
label: 'Label'
_17
}
_17
_17
// Add Owner B as a delegate of Owner A for all Safes accounts (safeAddress = null)
_17
const safeDelegateAddResponse = await apiKit.addSafeDelegate(delegateConfig)

Delete a delegate of a delegator


_10
const delegateConfig: DeleteSafeDelegateProps = {
_10
delegateAddress: ownerBAddress || '0x',
_10
delegatorAddress: ownerAAddress || '0x',
_10
signer: ownerA
_10
}
_10
_10
// Remove Owner B as delegate of Owner A
_10
await apiKit.removeSafeDelegate(delegateConfig)

Was this page helpful?