safe_eth.safe.api package

Subpackages

Submodules

safe_eth.safe.api.base_api module

exception safe_eth.safe.api.base_api.SafeAPIException

Bases: Exception

class safe_eth.safe.api.base_api.SafeBaseAPI(network: EthereumNetwork, ethereum_client: EthereumClient | None = None, base_url: str | None = None, api_key: str | None = None, request_timeout: int = 10)

Bases: ABC

classmethod from_ethereum_client(ethereum_client: EthereumClient, api_key: str | None = None) SafeBaseAPI

Module contents

exception safe_eth.safe.api.SafeAPIException

Bases: Exception

class safe_eth.safe.api.TransactionServiceApi(network: EthereumNetwork, ethereum_client: EthereumClient | None = None, base_url: str | None = None, api_key: str | None = None, request_timeout: int = 10)

Bases: SafeBaseAPI

NETWORK_SHORTNAME = {EthereumNetwork.ARBITRUM_ONE: 'arb1', EthereumNetwork.AURORA_MAINNET: 'aurora', EthereumNetwork.AVALANCHE_C_CHAIN: 'avax', EthereumNetwork.BASE: 'base', EthereumNetwork.BASE_SEPOLIA_TESTNET: 'basesep', EthereumNetwork.BERACHAIN: 'berachain', EthereumNetwork.BLAST: 'blastmainnet', EthereumNetwork.BNB_SMART_CHAIN_MAINNET: 'bnb', EthereumNetwork.CELO_MAINNET: 'celo', EthereumNetwork.GNOSIS: 'gno', EthereumNetwork.GNOSIS_CHIADO_TESTNET: 'chi', EthereumNetwork.HEMI_NETWORK: 'hemi', EthereumNetwork.INK: 'ink', EthereumNetwork.KATANA_MAINNET: 'katana', EthereumNetwork.LENS: 'lens', EthereumNetwork.LINEA: 'linea', EthereumNetwork.MAINNET: 'eth', EthereumNetwork.MANTLE: 'mantle', EthereumNetwork.OPTIMISM: 'oeth', EthereumNetwork.POLYGON: 'pol', EthereumNetwork.POLYGON_ZKEVM: 'zkevm', EthereumNetwork.SCROLL: 'scr', EthereumNetwork.SEPOLIA: 'sep', EthereumNetwork.SONIC_MAINNET: 'sonic', EthereumNetwork.UNICHAIN: 'unichain', EthereumNetwork.WORLD_CHAIN: 'wc', EthereumNetwork.X_LAYER_MAINNET: 'okb', EthereumNetwork.ZKSYNC_MAINNET: 'zksync'}
TRANSACTION_SERVICE_BASE_URL = 'https://api.safe.global/tx-service'
add_delegate(delegate_address: ChecksumAddress, delegator_address: ChecksumAddress, label: str, signature: bytes, safe_address: ChecksumAddress | None = None) bool
create_delegate_message_hash(delegate_address: ChecksumAddress) Hash32
classmethod data_decoded_to_text(data_decoded: Dict[str, Any]) str | None

Decoded data decoded to text :param data_decoded: :return:

decode_data(data: bytes | HexStr, to_address: ChecksumAddress | None = None) DataDecoded

Retrieve decoded information using tx service internal ABI information given the tx data.

Parameters:
  • data – tx data as a 0x prefixed hexadecimal string.

  • to_address – address of the contract. This will be used in case of more than one function identifiers matching.

Returns:

delete_transaction(safe_tx_hash: str, signature: str) bool
Parameters:
  • safe_tx_hash – hash of eip712 see in transaction_service_messages.py generate_remove_transaction_message function

  • signature – signature of safe_tx_hash by transaction proposer

Returns:

get_balances(safe_address: ChecksumAddress) List[Balance]
Parameters:

safe_address

Returns:

a list of balances for provided Safe

get_delegates(safe_address: ChecksumAddress) List[DelegateUser]
Parameters:

safe_address

Returns:

a list of delegates for provided Safe

get_message(safe_message_hash: bytes) Message
Parameters:

safe_message_hash

Returns:

Safe message for provided Safe message hash

get_messages(safe_address: ChecksumAddress) List[Message]
Parameters:

safe_address

Returns:

list of messages for provided Safe address

get_safe_transaction(safe_tx_hash: bytes | HexStr) Tuple[TransactionServiceTx, HexBytes | None]
Parameters:

safe_tx_hash

Returns:

SafeTx and tx-hash if transaction was executed

get_safes_for_owner(owner_address: ChecksumAddress) List[ChecksumAddress]
Parameters:

owner_address

Returns:

a List of Safe addresses which the owner_address is an owner

get_transactions(safe_address: ChecksumAddress, **kwargs: Dict[str, str | int | bool]) List[Transaction]
Parameters:

safe_address

Returns:

a list of transactions for provided Safe

classmethod parse_signatures(raw_tx: Transaction) bytes | None

Parse signatures in confirmations list to build a valid signature (owners must be sorted lexicographically)

Parameters:

raw_tx

Returns:

Valid signature with signatures sorted lexicographically

post_message(safe_address: ChecksumAddress, message: str | Dict, signature: bytes, safe_app_id: int | None = 0) bool

Create safe message on transaction service for provided Safe address

Parameters:
  • safe_address

  • message – If str it will be encoded using EIP191, and if it’s a dictionary it will be encoded using EIP712

  • signature

Returns:

post_message_signature(safe_message_hash: bytes, signature: bytes) bool

Add a new confirmation for provided Safe message hash

Parameters:
  • safe_message_hash

  • signature

Returns:

post_signatures(safe_tx_hash: bytes, signatures: bytes) bool

Create a new confirmation with provided signature for the given safe_tx_hash :param safe_tx_hash: :param signatures: :return: True if new confirmation was created

post_transaction(safe_tx: SafeTx) bool
remove_delegate(delegate_address: ChecksumAddress, delegator_address: ChecksumAddress, signature: bytes, safe_address: ChecksumAddress | None = None) bool

Deletes a delegated user

Parameters:
  • delegator_address

  • delegate_address

  • signature – Signature of a hash of an eip712 message.

  • safe_address – If specified, a delegate is removed for a delegator for the specific safe. Otherwise, the delegate is deleted in a global form.

Returns: