npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rndlabs/safe-api-kit

v1.0.4

Published

Safe API Kit

Downloads

16

Readme

Safe API Kit

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 run build

Tests

Create a .env file with environment variables. You can use the .env.example file as a reference.

Test the package with yarn or npm:

yarn test
npm run test

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 SafeApiKit

import SafeApiKit from '@rndlabs/safe-api-kit'

const safeService = new SafeApiKit({
  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 delegateConfig: GetSafeDelegateProps = {
  safeAddress, // Optional
  delegateAddress, // Optional
  delegatorAddress, // Optional
  label, // Optional
  limit, // Optional
  offset // Optional
}
const delegates: SafeDelegateListResponse = await safeService.getSafeDelegates(delegateConfig)

addSafeDelegate

Adds a new delegate for a given Safe address.

const delegateConfig: AddSafeDelegateProps = {
  safeAddress, // Optional
  delegateAddress,
  delegatorAddress,
  label,
  signer
}
await safeService.addSafeDelegate(delegateConfig)

removeSafeDelegate

Removes a delegate for a given Safe address.

const delegateConfig: DeleteSafeDelegateProps = {
  delegateAddress,
  delegatorAddress,
  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)

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