@gnosis.pm/safe-service-client

中文文档
1.4.0发布于 2022/11/23MITTypeScriptCommonJS近 30 天下载 3714

Safe Service Client

此软件包已被标记为弃用

Package no longer supported. It has been migrated to @safe-global/api-kit. Please, update your dependencies.

原始使用文档
文档目录36 节
  1. Table of contents
  2. Installation
  3. Build
  4. Initialization
  5. Instantiate an EthAdapter
  6. Initialize the SafeServiceClient
  7. API Reference
  8. getServiceInfo
  9. getServiceMasterCopiesInfo
  10. decodeData
  11. getSafesByOwner
  12. getSafesByModule
  13. getTransaction
  14. getTransactionConfirmations
  15. confirmTransaction
  16. getSafeInfo
  17. getSafeDelegates
  18. addSafeDelegate
  19. removeAllSafeDelegates
  20. removeSafeDelegate
  21. getSafeCreationInfo
  22. estimateSafeTransaction
  23. proposeTransaction
  24. getIncomingTransactions
  25. getModuleTransactions
  26. getMultisigTransactions
  27. getPendingTransactions
  28. getAllTransactions
  29. getNextNonce
  30. getBalances
  31. getUsdBalances
  32. getCollectibles
  33. getTokenList
  34. getToken
  35. License
  36. Contributors

Safe Service Client

NPM Version GitHub Release GitHub

Software development kit that facilitates the interaction with the Safe Transaction Service API.

Table of contents

Installation

Install the package with yarn or npm:

yarn install
npm install

Build

Build the package with yarn or npm:

yarn build
npm build

Initialization

Instantiate an EthAdapter

First of all, we need to create an EthAdapter, which contains all the required utilities for the SDKs to interact with the blockchain. It acts as a wrapper for web3.js or ethers.js Ethereum libraries.

Depending on the library used by the Dapp, there are two options:

Once the instance of EthersAdapter or Web3Adapter is created, it can be used in the SDK initialization.

Initialize the SafeServiceClient

import SafeServiceClient from '@gnosis.pm/safe-service-client'

const safeService = new SafeServiceClient({
  txServiceUrl: 'https://safe-transaction-mainnet.safe.global',
  ethAdapter
})

API Reference

getServiceInfo

Returns the information and configuration of the service.

const serviceInfo: SafeServiceInfoResponse = await safeService.getServiceInfo()

getServiceMasterCopiesInfo

Returns the list of Safe master copies.

const masterCopies: MasterCopyResponse = await safeService.getServiceMasterCopiesInfo()

decodeData

Decodes the specified Safe transaction data.

const decodedData = await safeService.decodeData(data)

getSafesByOwner

Returns the list of Safes where the address provided is an owner.

const safes: OwnerResponse = await safeService.getSafesByOwner(ownerAddress)

getSafesByModule

Returns the list of Safes where the module address provided is enabled.

const safes: ModulesResponse = await getSafesByModule(moduleAddress)

getTransaction

Returns all the information of a Safe transaction.

const tx: SafeMultisigTransactionResponse = await safeService.getTransaction(safeTxHash)

getTransactionConfirmations

Returns the list of confirmations for a given a Safe transaction.

const confirmations: SafeMultisigConfirmationListResponse = await safeService.getTransactionConfirmations(safeTxHash)

confirmTransaction

Adds a confirmation for a Safe transaction.

const signature: SignatureResponse = await safeService.confirmTransaction(safeTxHash, signature)

getSafeInfo

Returns the information and configuration of the provided Safe address.

const safeInfo: SafeInfoResponse = await safeService.getSafeInfo(safeAddress)

getSafeDelegates

Returns the list of delegates for a given Safe address.

const delegates: SafeDelegateListResponse = await safeService.getSafeDelegates(safeAddress)

addSafeDelegate

Adds a new delegate for a given Safe address.

const delegateConfig: SafeDelegateConfig = {
  safe,
  delegate,
  label,
  signer
}
await safeService.addSafeDelegate(delegateConfig)

removeAllSafeDelegates

Removes all delegates for a given Safe address.

await safeService.removeAllSafeDelegates(safeAddress, signer)

removeSafeDelegate

Removes a delegate for a given Safe address.

const delegateConfig: SafeDelegateDeleteConfig = {
  safe,
  delegate,
  signer
}
await safeService.removeSafeDelegate(delegateConfig)

getSafeCreationInfo

Returns the creation information of a Safe.

const safeCreationInfo: SafeCreationInfoResponse = await safeService.getSafeCreationInfo(safeAddress)

estimateSafeTransaction

Estimates the safeTxGas for a given Safe multi-signature transaction.

const estimateTx: SafeMultisigTransactionEstimateResponse = await safeService.estimateSafeTransaction(
  safeAddress,
  safeTransaction
)

proposeTransaction

Creates a new multi-signature transaction and stores it in the Safe Transaction Service.

const transactionConfig: ProposeTransactionProps = {
  safeAddress,
  safeTxHash,
  safeTransactionData,
  senderAddress,
  senderSignature,
  origin
}
await safeService.proposeTransaction(transactionConfig)

getIncomingTransactions

Returns the history of incoming transactions of a Safe account.

const incomingTxs: TransferListResponse = await safeService.getIncomingTransactions(safeAddress)

getModuleTransactions

Returns the history of module transactions of a Safe account.

const moduleTxs: SafeModuleTransactionListResponse = await safeService.getModuleTransactions(safeAddress)

getMultisigTransactions

Returns the history of multi-signature transactions of a Safe account.

const multisigTxs: SafeMultisigTransactionListResponse = await safeService.getMultisigTransactions(safeAddress)

getPendingTransactions

Returns the list of multi-signature transactions that are waiting for the confirmation of the Safe owners.

const pendingTxs: SafeMultisigTransactionListResponse = await safeService.getPendingTransactions(safeAddress)
const pendingTxs: SafeMultisigTransactionListResponse = await safeService.getPendingTransactions(
  safeAddress,
  currentNonce
)

getAllTransactions

Returns a list of transactions for a Safe. The list has different structures depending on the transaction type.

const allTxs: SafeMultisigTransactionListResponse = await safeService.getAllTransactions(safeAddress)
const allTxsOptions: AllTransactionsOptions = {
  executed,
  queued,
  trusted
}
const allTxs: SafeMultisigTransactionListResponse = await safeService.getAllTransactions(
  safeAddress,
  allTxsOptions
)

getNextNonce

Returns the right nonce to propose a new transaction right after the last pending transaction.

const nextNonce = await safeService.getNextNonce(safeAddress)

getBalances

Returns the balances for Ether and ERC20 tokens of a Safe.

const balances: SafeBalanceResponse[] = await safeService.getBalances(safeAddress)

This method can optionally receive the options parameter:

const options: SafeBalancesOptions = {
  excludeSpamTokens  // Optional. Default value is `true`.
}
const balances: SafeBalanceResponse[] = await safeService.getBalances(safeAddress, options)

getUsdBalances

Returns the balances for Ether and ERC20 tokens of a Safe with USD fiat conversion.

const usdBalances: SafeBalanceUsdResponse[] = await safeService.getUsdBalances(safeAddress)

This method can optionally receive the options parameter:

const options: SafeBalancesUsdOptions = {
  excludeSpamTokens // Optional. Default value is `true`.
}
const usdBalances: SafeBalanceUsdResponse[] = await safeService.getUsdBalances(safeAddress, options)

getCollectibles

Returns the collectives (ERC721 tokens) owned by the given Safe and information about them.

const collectibles: SafeCollectibleResponse[] = await safeService.getCollectibles(safeAddress)

This method can optionally receive the options parameter:

const options: SafeCollectiblesOptions = {
  excludeSpamTokens // Optional. Default value is `true`.
}
const collectibles: SafeCollectibleResponse[] = await safeService.getCollectibles(safeAddress, options)

getTokenList

Returns the list of all the ERC20 tokens handled by the Safe.

const tokens: TokenInfoListResponse = await safeService.getTokenList()

getToken

Returns the information of a given ERC20 token.

const token: TokenInfoResponse = await safeService.getToken(tokenAddress)

License

This library is released under MIT.

Contributors

版本与发布记录

@gnosis.pm/safe-service-client 共发布 12 个版本,首次发布于 2021/06/03;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.4.0latest2022/11/233 年前
1.3.12022/09/224 年前
1.3.02022/09/214 年前
1.2.02022/07/154 年前
1.1.22022/04/054 年前
1.1.12022/02/014 年前

关于 @gnosis.pm/safe-service-client 的常见问题

@gnosis.pm/safe-service-client 是什么?

Safe Service Client注意:该包已被作者标记为弃用——Package no longer supported. It has been migrated to @safe-global/api-kit. Please, update your dependencies.

如何安装 @gnosis.pm/safe-service-client?

在项目目录运行 npm install @gnosis.pm/safe-service-client,或使用 pnpm add / yarn add / bun add。

@gnosis.pm/safe-service-client 支持 TypeScript 吗?

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

@gnosis.pm/safe-service-client 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@gnosis.pm/safe-service-client 可以商用吗?

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

@gnosis.pm/safe-service-client 的下载量有多少?

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

@gnosis.pm/safe-service-client 还在维护吗?

最新版本 1.4.0 发布于 2022/11/23(3 年前);至今共发布 12 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/06/03。作者已将其标记为弃用,新项目建议寻找替代方案。