Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@safe-global/safe-gateway-typescript-sdk
Advanced tools
[![npm](https://img.shields.io/npm/v/@safe-global/safe-gateway-typescript-sdk?label=%40safe-global%2Fsafe-gateway-typescript-sdk)](https://www.npmjs.com/package/@safe-global/safe-gateway-typescript-sdk)
@safe-global/safe-gateway-typescript-sdk is a TypeScript SDK for interacting with the Safe Global Gateway API. It allows developers to manage and interact with Safe (formerly Gnosis Safe) smart contracts, providing functionalities such as retrieving Safe information, transaction history, and managing transactions.
Retrieve Safe Information
This feature allows you to retrieve information about a specific Safe, such as its owners, threshold, and nonce.
const { SafeGatewayClient } = require('@safe-global/safe-gateway-typescript-sdk');
const client = new SafeGatewayClient('https://safe-transaction.mainnet.gnosis.io');
async function getSafeInfo(safeAddress) {
const safeInfo = await client.getSafeInfo(safeAddress);
console.log(safeInfo);
}
getSafeInfo('0xYourSafeAddress');
Retrieve Transaction History
This feature allows you to retrieve the transaction history of a specific Safe, including executed and pending transactions.
const { SafeGatewayClient } = require('@safe-global/safe-gateway-typescript-sdk');
const client = new SafeGatewayClient('https://safe-transaction.mainnet.gnosis.io');
async function getTransactionHistory(safeAddress) {
const history = await client.getTransactionHistory(safeAddress);
console.log(history);
}
getTransactionHistory('0xYourSafeAddress');
Propose a Transaction
This feature allows you to propose a new transaction for a specific Safe. The transaction can then be confirmed by the required number of owners.
const { SafeGatewayClient } = require('@safe-global/safe-gateway-typescript-sdk');
const client = new SafeGatewayClient('https://safe-transaction.mainnet.gnosis.io');
async function proposeTransaction(safeAddress, transaction) {
const response = await client.proposeTransaction(safeAddress, transaction);
console.log(response);
}
const transaction = {
to: '0xRecipientAddress',
value: '1000000000000000000', // 1 ETH in wei
data: '0x',
operation: 0
};
proposeTransaction('0xYourSafeAddress', transaction);
The ethers.js library is a complete and compact library for interacting with the Ethereum blockchain and its ecosystem. It provides functionalities for managing wallets, interacting with smart contracts, and querying blockchain data. Compared to @safe-global/safe-gateway-typescript-sdk, ethers.js offers a broader range of functionalities but does not specifically target Safe smart contracts.
The web3.js library is a collection of modules that contain functionalities for the Ethereum ecosystem. It allows developers to interact with Ethereum nodes, manage accounts, and interact with smart contracts. Similar to ethers.js, web3.js provides a wide range of functionalities but does not specifically focus on Safe smart contracts.
The gnosis-safe npm package is a JavaScript library for interacting with Gnosis Safe smart contracts. It provides functionalities for creating, managing, and interacting with Gnosis Safe wallets. While it offers similar functionalities to @safe-global/safe-gateway-typescript-sdk, it is not specifically designed as a TypeScript SDK and may lack some of the type safety and developer experience improvements.
A TypeScript SDK for the Safe Client Gateway
📖 Type reference | CGW Swagger
NB: Safe Client Gateway isn't meant for public use. Please do not use this SDK if you're building, e.g., a Safe App.
Install:
yarn add @safe-global/safe-gateway-typescript-sdk
Import:
import { getChainsConfig, type ChainListResponse } from '@safe-global/safe-gateway-typescript-sdk'
Use:
const chains = await getChainsConfig()
The SDK needs no initialization unless you want to override the base URL. You can set an alternative base URL like so:
import { setBaseUrl } from '@safe-global/safe-gateway-typescript-sdk'
// Switch the SDK to dev mode
setBaseUrl('https://safe-client.staging.5afe.dev')
The full SDK reference can be found here.
Endpoint types are defined in src/types/gateway.ts
.
Each endpoint consists of:
src/index.ts
(e.g. getBalances
)'/chains/{chainId}/safes/{address}/balances/{currency}/'
)safes_balances_list
)To add a new endpoint, follow the pattern set by the existing endpoints.
This command will run before every commit:
yarn eslint:fix
To run the unit and e2e tests locally:
yarn test
N.B.: the e2e tests make actual API calls on staging.
FAQs
[![npm](https://img.shields.io/npm/v/@safe-global/safe-gateway-typescript-sdk?label=%40safe-global%2Fsafe-gateway-typescript-sdk)](https://www.npmjs.com/package/@safe-global/safe-gateway-typescript-sdk)
The npm package @safe-global/safe-gateway-typescript-sdk receives a total of 173,749 weekly downloads. As such, @safe-global/safe-gateway-typescript-sdk popularity was classified as popular.
We found that @safe-global/safe-gateway-typescript-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.