safe_eth.safe.api.transaction_service_api package

Submodules

safe_eth.safe.api.transaction_service_api.entities module

class safe_eth.safe.api.transaction_service_api.entities.Balance

Bases: TypedDict

balance: int
token: Erc20Info | None
token_address: Address | HexAddress | ChecksumAddress | None
class safe_eth.safe.api.transaction_service_api.entities.DataDecoded

Bases: TypedDict

method: str
parameters: List[ParameterDecoded]
class safe_eth.safe.api.transaction_service_api.entities.DelegateUser

Bases: TypedDict

delegate: Address | HexAddress | ChecksumAddress
delegator: Address | HexAddress | ChecksumAddress
label: str
safe: Address | HexAddress | ChecksumAddress | None
class safe_eth.safe.api.transaction_service_api.entities.Erc20Info

Bases: TypedDict

decimals: int
logo_uri: str
name: str
symbol: str
class safe_eth.safe.api.transaction_service_api.entities.Message

Bases: TypedDict

confirmations: List[MessageConfirmation] | None
created: str
message: Any
messageHash: HexStr
modified: str
preparedSignature: HexStr | None
proposedBy: Address | HexAddress | ChecksumAddress
safe: Address | HexAddress | ChecksumAddress
safeAppId: int
class safe_eth.safe.api.transaction_service_api.entities.MessageConfirmation

Bases: TypedDict

created: str
modified: str
owner: Address | HexAddress | ChecksumAddress
signature: HexStr
signatureType: str
class safe_eth.safe.api.transaction_service_api.entities.ParameterDecoded

Bases: TypedDict

name: str
type: str
value: Any
class safe_eth.safe.api.transaction_service_api.entities.Transaction

Bases: TypedDict

baseGas: str
blockNumber: int | None
confirmations: List[TransactionConfirmation] | None
confirmationsRequired: int
data: HexStr | None
dataDecoded: List[DataDecoded] | None
ethGasPrice: str | None
execution_date: str
executor: Address | HexAddress | ChecksumAddress | None
fee: int | None
gasPrice: str
gasToken: Address | HexAddress | ChecksumAddress | None
gasUsed: int | None
isExecuted: bool
isSuccessful: bool | None
maxFeePerGas: str | None
maxPriorityFeePerGas: str | None
modified: str
nonce: str
operation: int
origin: str | None
proposer: Address | HexAddress | ChecksumAddress
refundReceiver: Address | HexAddress | ChecksumAddress | None
safe: Address | HexAddress | ChecksumAddress
safeTxGas: str
safeTxHash: HexStr
signatures: HexStr | None
submission_date: str
to: Address | HexAddress | ChecksumAddress
transactionHash: HexStr
trusted: bool
value: str
class safe_eth.safe.api.transaction_service_api.entities.TransactionConfirmation

Bases: TypedDict

owner: Address | HexAddress | ChecksumAddress
signature: HexStr
signatureType: str
submissionDate: str
transactionHash: HexStr

safe_eth.safe.api.transaction_service_api.transaction_service_api module

exception safe_eth.safe.api.transaction_service_api.transaction_service_api.ApiSafeTxHashNotMatchingException

Bases: SafeAPIException

class safe_eth.safe.api.transaction_service_api.transaction_service_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:

safe_eth.safe.api.transaction_service_api.transaction_service_messages module

Utilities to build EIP712 messages for Safe

safe_eth.safe.api.transaction_service_api.transaction_service_messages.get_delegate_message(delegate_address: ChecksumAddress, chain_id: int) Dict[str, Any]

Retrieves the required message for creating or removing a delegate on Safe Transaction Service.

Parameters:
  • delegate_address

  • chain_id

Returns:

generated EIP712 message

safe_eth.safe.api.transaction_service_api.transaction_service_messages.get_remove_transaction_message(safe_address: ChecksumAddress, safe_tx_hash: bytes, chain_id: int) Dict[str, Any]

Retrieves the required message for removing a not executed transaction on Safe Transaction Service.

Parameters:
  • safe_address

  • safe_tx_hash

  • chain_id

Returns:

generated EIP712 message

safe_eth.safe.api.transaction_service_api.transaction_service_messages.get_totp() int
Returns:

time-based one-time password

safe_eth.safe.api.transaction_service_api.transaction_service_tx module

class safe_eth.safe.api.transaction_service_api.transaction_service_tx.TransactionServiceTx(proposer: ChecksumAddress | None, *args, **kwargs)

Bases: SafeTx

Module contents

exception safe_eth.safe.api.transaction_service_api.ApiSafeTxHashNotMatchingException

Bases: SafeAPIException

class safe_eth.safe.api.transaction_service_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: