gnosis.safe package

Subpackages

Submodules

gnosis.safe.exceptions module

exception gnosis.safe.exceptions.CannotEstimateGas

Bases: SafeServiceException

exception gnosis.safe.exceptions.CannotRetrieveSafeInfoException

Bases: SafeServiceException

exception gnosis.safe.exceptions.CouldNotFinishInitialization

Bases: InvalidMultisigTx

exception gnosis.safe.exceptions.CouldNotPayGasWithEther

Bases: InvalidMultisigTx

exception gnosis.safe.exceptions.CouldNotPayGasWithToken

Bases: InvalidMultisigTx

exception gnosis.safe.exceptions.HashHasNotBeenApproved

Bases: InvalidMultisigTx

exception gnosis.safe.exceptions.InvalidChecksumAddress

Bases: SafeServiceException

exception gnosis.safe.exceptions.InvalidContractSignatureLocation

Bases: InvalidMultisigTx

exception gnosis.safe.exceptions.InvalidInternalTx

Bases: InvalidMultisigTx

exception gnosis.safe.exceptions.InvalidMultisigTx

Bases: SafeServiceException

exception gnosis.safe.exceptions.InvalidOwnerProvided

Bases: InvalidMultisigTx

exception gnosis.safe.exceptions.InvalidPaymentToken

Bases: SafeServiceException

exception gnosis.safe.exceptions.InvalidSignaturesProvided

Bases: InvalidMultisigTx

exception gnosis.safe.exceptions.MethodCanOnlyBeCalledFromThisContract

Bases: InvalidMultisigTx

exception gnosis.safe.exceptions.ModuleManagerException

Bases: InvalidMultisigTx

exception gnosis.safe.exceptions.NotEnoughSafeTransactionGas

Bases: InvalidMultisigTx

exception gnosis.safe.exceptions.OnlyOwnersCanApproveAHash

Bases: InvalidMultisigTx

exception gnosis.safe.exceptions.OwnerManagerException

Bases: InvalidMultisigTx

exception gnosis.safe.exceptions.SafeServiceException

Bases: Exception

exception gnosis.safe.exceptions.SafeTransactionFailedWhenGasPriceAndSafeTxGasEmpty

Bases: InvalidMultisigTx

exception gnosis.safe.exceptions.SignatureNotProvidedByOwner

Bases: InvalidMultisigTx

exception gnosis.safe.exceptions.SignaturesDataTooShort

Bases: InvalidMultisigTx

exception gnosis.safe.exceptions.ThresholdNeedsToBeDefined

Bases: InvalidMultisigTx

gnosis.safe.multi_send module

class gnosis.safe.multi_send.MultiSend(address: str, ethereum_client: EthereumClient)

Bases: object

build_tx_data(multi_send_txs: List[MultiSendTx]) bytes

Txs don’t need to be valid to get through

Parameters
  • multi_send_txs

  • sender

Returns

static deploy_contract(ethereum_client: EthereumClient, deployer_account: LocalAccount) EthereumTxSent

Deploy proxy factory contract

Parameters
  • ethereum_client

  • deployer_account – Ethereum Account

Returns

deployed contract address

dummy_w3 = <web3.main.Web3 object>
classmethod from_bytes(encoded_multisend_txs: Union[str, bytes]) List[MultiSendTx]

Decodes one or more multisend transactions from bytes transactions (Abi decoded)

Parameters

encoded_multisend_txs

Returns

List of MultiSendTxs

classmethod from_transaction_data(multisend_data: Union[str, bytes]) List[MultiSendTx]

Decodes multisend transactions from transaction data (ABI encoded with selector)

Returns

get_contract()
class gnosis.safe.multi_send.MultiSendOperation(value)

Bases: Enum

An enumeration.

CALL = 0
DELEGATE_CALL = 1
class gnosis.safe.multi_send.MultiSendTx(operation: MultiSendOperation, to: str, value: int, data: Union[bytes, HexStr], old_encoding: bool = False)

Bases: object

Wrapper for a single MultiSendTx

property data_length: int
property encoded_data
classmethod from_bytes(encoded_multisend_tx: Union[str, bytes]) MultiSendTx

Decoded one MultiSend transaction. ABI must be used to get the transactions parameter and use that data for this function :param encoded_multisend_tx: :return:

gnosis.safe.proxy_factory module

class gnosis.safe.proxy_factory.ProxyFactory(address: ChecksumAddress, ethereum_client: EthereumClient)

Bases: object

check_proxy_code(address: ChecksumAddress) bool

Check if proxy is valid :param address: Ethereum address to check :return: True if proxy is valid, False otherwise

deploy_proxy_contract(deployer_account: LocalAccount, master_copy: ChecksumAddress, initializer: bytes = b'', gas: Optional[int] = None, gas_price: Optional[int] = None) EthereumTxSent

Deploy proxy contract via ProxyFactory using createProxy function :param deployer_account: Ethereum account :param master_copy: Address the proxy will point at :param initializer: Initializer :param gas: Gas :param gas_price: Gas Price :return: EthereumTxSent

deploy_proxy_contract_with_nonce(deployer_account: LocalAccount, master_copy: ChecksumAddress, initializer: bytes, salt_nonce: int, gas: Optional[int] = None, gas_price: Optional[int] = None, nonce: Optional[int] = None) EthereumTxSent

Deploy proxy contract via Proxy Factory using createProxyWithNonce (create2)

Parameters
  • deployer_account – Ethereum account

  • master_copy – Address the proxy will point at

  • initializer – Data for safe creation

  • salt_nonce – Uint256 for create2 salt

  • gas – Gas

  • gas_price – Gas Price

  • nonce – Nonce

Returns

Tuple(tx-hash, tx, deployed contract address)

classmethod deploy_proxy_factory_contract(ethereum_client: EthereumClient, deployer_account: LocalAccount) EthereumTxSent

Deploy proxy factory contract last version (v1.3.0)

Parameters
  • ethereum_client

  • deployer_account – Ethereum Account

Returns

deployed contract address

classmethod deploy_proxy_factory_contract_v1_0_0(ethereum_client: EthereumClient, deployer_account: LocalAccount) EthereumTxSent

Deploy proxy factory contract v1.0.0

Parameters
  • ethereum_client

  • deployer_account – Ethereum Account

Returns

deployed contract address

classmethod deploy_proxy_factory_contract_v1_1_1(ethereum_client: EthereumClient, deployer_account: LocalAccount) EthereumTxSent

Deploy proxy factory contract v1.1.1

Parameters
  • ethereum_client

  • deployer_account – Ethereum Account

Returns

deployed contract address

get_contract(address: Optional[ChecksumAddress] = None)
get_proxy_runtime_code(address: Optional[ChecksumAddress] = None)

Get runtime code for current proxy factory

gnosis.safe.safe module

class gnosis.safe.safe.Safe(address: ChecksumAddress, ethereum_client: EthereumClient)

Bases: object

Class to manage a Gnosis Safe

FALLBACK_HANDLER_STORAGE_SLOT = 49122629484629529244014240937346711770925847994644146912111677022347558721749
GUARD_STORAGE_SLOT = 33528237782592280163068556224972516439282563014722366175641814928123294921928
build_multisig_tx(to: str, value: int, data: bytes, operation: int = 0, safe_tx_gas: int = 0, base_gas: int = 0, gas_price: int = 0, gas_token: str = '0x0000000000000000000000000000000000000000', refund_receiver: str = '0x0000000000000000000000000000000000000000', signatures: bytes = b'', safe_nonce: Optional[int] = None, safe_version: Optional[str] = None) SafeTx

Allows to execute a Safe transaction confirmed by required number of owners and then pays the account that submitted the transaction. The fees are always transfered, even if the user transaction fails

Parameters
  • to – Destination address of Safe transaction

  • value – Ether value of Safe transaction

  • data – Data payload of Safe transaction

  • operation – Operation type of Safe transaction

  • safe_tx_gas – Gas that should be used for the Safe transaction

  • base_gas – Gas costs for that are independent of the transaction execution (e.g. base transaction fee, signature check, payment of the refund)

  • gas_price – Gas price that should be used for the payment calculation

  • gas_token – Token address (or 0x000..000 if ETH) that is used for the payment

  • refund_receiver – Address of receiver of gas payment (or 0x000..000 if tx.origin).

  • signatures – Packed signature data ({bytes32 r}{bytes32 s}{uint8 v})

  • safe_nonce – Nonce of the safe (to calculate hash)

  • safe_version – Safe version (to calculate hash)

Returns

static build_safe_create2_tx(ethereum_client: EthereumClient, master_copy_address: str, proxy_factory_address: str, salt_nonce: int, owners: List[str], threshold: int, gas_price: int, payment_token: Optional[str], payment_receiver: Optional[str] = None, fallback_handler: Optional[str] = '0x0000000000000000000000000000000000000000', payment_token_eth_value: float = 1.0, fixed_creation_cost: Optional[int] = None) SafeCreate2Tx

Prepare safe proxy deployment for being relayed. It calculates and sets the costs of deployment to be returned to the sender of the tx. If you are an advanced user you may prefer to use create function

static build_safe_creation_tx(ethereum_client: EthereumClient, master_copy_old_address: str, s: int, owners: List[str], threshold: int, gas_price: int, payment_token: Optional[str], payment_receiver: str, payment_token_eth_value: float = 1.0, fixed_creation_cost: Optional[int] = None) SafeCreationTx
check_funds_for_tx_gas(safe_tx_gas: int, base_gas: int, gas_price: int, gas_token: str) bool

Check safe has enough funds to pay for a tx

Parameters
  • safe_tx_gas – Safe tx gas

  • base_gas – Data gas

  • gas_price – Gas Price

  • gas_token – Gas Token, to use token instead of ether for the gas

Returns

True if enough funds, False otherwise

static create(ethereum_client: EthereumClient, deployer_account: LocalAccount, master_copy_address: str, owners: List[str], threshold: int, fallback_handler: str = '0x0000000000000000000000000000000000000000', proxy_factory_address: Optional[str] = None, payment_token: str = '0x0000000000000000000000000000000000000000', payment: int = 0, payment_receiver: str = '0x0000000000000000000000000000000000000000') EthereumTxSent

Deploy new Safe proxy pointing to the specified master_copy address and configured with the provided owners and threshold. By default, payment for the deployer of the tx will be 0. If proxy_factory_address is set deployment will be done using the proxy factory instead of calling the constructor of a new DelegatedProxy Using proxy_factory_address is recommended, as it takes less gas. (Testing with Ganache and 1 owner 261534 without proxy vs 229022 with Proxy)

classmethod deploy_compatibility_fallback_handler(ethereum_client: EthereumClient, deployer_account: LocalAccount) EthereumTxSent

Deploy Compatibility Fallback handler v1.3.0

Parameters
  • ethereum_client

  • deployer_account – Ethereum account

Returns

deployed contract address

static deploy_master_contract_v0_0_1(ethereum_client: EthereumClient, deployer_account: LocalAccount) EthereumTxSent

Deploy master contract. Takes deployer_account (if unlocked in the node) or the deployer private key

Parameters
  • ethereum_client

  • deployer_account – Ethereum account

Returns

deployed contract address

static deploy_master_contract_v1_0_0(ethereum_client: EthereumClient, deployer_account: LocalAccount) EthereumTxSent

Deploy master contract. Takes deployer_account (if unlocked in the node) or the deployer private key

Parameters
  • ethereum_client

  • deployer_account – Ethereum account

Returns

deployed contract address

classmethod deploy_master_contract_v1_1_1(ethereum_client: EthereumClient, deployer_account: LocalAccount) EthereumTxSent

Deploy master contract v1.1.1. Takes deployer_account (if unlocked in the node) or the deployer private key Safe with version > v1.1.1 doesn’t need to be initialized as it already has a constructor

Parameters
  • ethereum_client

  • deployer_account – Ethereum account

Returns

deployed contract address

classmethod deploy_master_contract_v1_3_0(ethereum_client: EthereumClient, deployer_account: LocalAccount) EthereumTxSent

Deploy master contract v1.3.0. Takes deployer_account (if unlocked in the node) or the deployer private key Safe with version > v1.1.1 doesn’t need to be initialized as it already has a constructor

Parameters
  • ethereum_client

  • deployer_account – Ethereum account

Returns

deployed contract address

static estimate_safe_creation(ethereum_client: EthereumClient, old_master_copy_address: str, number_owners: int, gas_price: int, payment_token: Optional[str], payment_receiver: str = '0x0000000000000000000000000000000000000000', payment_token_eth_value: float = 1.0, fixed_creation_cost: Optional[int] = None) SafeCreationEstimate
static estimate_safe_creation_2(ethereum_client: EthereumClient, master_copy_address: str, proxy_factory_address: str, number_owners: int, gas_price: int, payment_token: Optional[str], payment_receiver: str = '0x0000000000000000000000000000000000000000', fallback_handler: Optional[str] = None, payment_token_eth_value: float = 1.0, fixed_creation_cost: Optional[int] = None) SafeCreationEstimate
estimate_tx_base_gas(to: str, value: int, data: bytes, operation: int, gas_token: str, estimated_tx_gas: int) int

Calculate gas costs that are independent of the transaction execution(e.g. base transaction fee, signature check, payment of the refund…)

Parameters
  • to

  • value

  • data

  • operation

  • gas_token

  • estimated_tx_gas – gas calculated with estimate_tx_gas

Returns

estimate_tx_gas(to: str, value: int, data: bytes, operation: int) int

Estimate tx gas. Use requiredTxGas on the Safe contract and fallbacks to eth_estimateGas if that method fails. Note: eth_estimateGas cannot estimate delegate calls

Parameters
  • to

  • value

  • data

  • operation

Returns

Estimated gas for Safe inner tx

Raises

CannotEstimateGas

estimate_tx_gas_by_trying(to: str, value: int, data: Union[bytes, str], operation: int)

Try to get an estimation with Safe’s requiredTxGas. If estimation if successful, try to set a gas limit and estimate again. If gas estimation is ok, same gas estimation should be returned, if it’s less than required estimation will not be completed, so estimation was not accurate and gas limit needs to be increased.

Parameters
  • to

  • value

  • data

  • operation

Returns

Estimated gas calling requiredTxGas setting a gas limit and checking if eth_call is successful

Raises

CannotEstimateGas

estimate_tx_gas_with_safe(to: str, value: int, data: bytes, operation: int, gas_limit: Optional[int] = None, block_identifier: Optional[Union[Literal['latest', 'earliest', 'pending'], BlockNumber, Hash32, HexStr, HexBytes, int]] = 'latest') int

Estimate tx gas using safe requiredTxGas method

Returns

int: Estimated gas

Raises

CannotEstimateGas: If gas cannot be estimated

Raises

ValueError: Cannot decode received data

estimate_tx_gas_with_web3(to: str, value: int, data: Union[bytes, HexStr]) int
Parameters
  • to

  • value

  • data

Returns

Estimation using web3 estimate_gas

estimate_tx_operational_gas(data_bytes_length: int)

DEPRECATED. estimate_tx_base_gas already includes this. Estimates the gas for the verification of the signatures and other safe related tasks before and after executing a transaction. Calculation will be the sum of:

  • Base cost of 15000 gas

  • 100 of gas per word of data_bytes

  • Validate the signatures 5000 * threshold (ecrecover for ecdsa ~= 4K gas)

Parameters

data_bytes_length – Length of the data (in bytes, so len(HexBytes(‘0x12’)) would be 1

Returns

gas costs per signature * threshold of Safe

get_contract() Contract
retrieve_all_info(block_identifier: Optional[Union[Literal['latest', 'earliest', 'pending'], BlockNumber, Hash32, HexStr, HexBytes, int]] = 'latest') SafeInfo

Get all Safe info in the same batch call.

Parameters

block_identifier

Returns

Raises

CannotRetrieveSafeInfoException

retrieve_code() HexBytes
retrieve_fallback_handler(block_identifier: Optional[Union[Literal['latest', 'earliest', 'pending'], BlockNumber, Hash32, HexStr, HexBytes, int]] = 'latest') ChecksumAddress
retrieve_guard(block_identifier: Optional[Union[Literal['latest', 'earliest', 'pending'], BlockNumber, Hash32, HexStr, HexBytes, int]] = 'latest') ChecksumAddress
retrieve_is_hash_approved(owner: str, safe_hash: bytes, block_identifier: Optional[Union[Literal['latest', 'earliest', 'pending'], BlockNumber, Hash32, HexStr, HexBytes, int]] = 'latest') bool
retrieve_is_message_signed(message_hash: bytes, block_identifier: Optional[Union[Literal['latest', 'earliest', 'pending'], BlockNumber, Hash32, HexStr, HexBytes, int]] = 'latest') bool
retrieve_is_owner(owner: str, block_identifier: Optional[Union[Literal['latest', 'earliest', 'pending'], BlockNumber, Hash32, HexStr, HexBytes, int]] = 'latest') bool
retrieve_master_copy_address(block_identifier: Optional[Union[Literal['latest', 'earliest', 'pending'], BlockNumber, Hash32, HexStr, HexBytes, int]] = 'latest') ChecksumAddress
retrieve_modules(pagination: Optional[int] = 50, block_identifier: Optional[Union[Literal['latest', 'earliest', 'pending'], BlockNumber, Hash32, HexStr, HexBytes, int]] = 'latest') List[str]
Parameters
  • pagination – Number of modules to get per request

  • block_identifier

Returns

List of module addresses

retrieve_nonce(block_identifier: Optional[Union[Literal['latest', 'earliest', 'pending'], BlockNumber, Hash32, HexStr, HexBytes, int]] = 'latest') int
retrieve_owners(block_identifier: Optional[Union[Literal['latest', 'earliest', 'pending'], BlockNumber, Hash32, HexStr, HexBytes, int]] = 'latest') List[str]
retrieve_threshold(block_identifier: Optional[Union[Literal['latest', 'earliest', 'pending'], BlockNumber, Hash32, HexStr, HexBytes, int]] = 'latest') int
retrieve_version(block_identifier: Optional[Union[Literal['latest', 'earliest', 'pending'], BlockNumber, Hash32, HexStr, HexBytes, int]] = 'latest') str
send_multisig_tx(to: str, value: int, data: bytes, operation: int, safe_tx_gas: int, base_gas: int, gas_price: int, gas_token: str, refund_receiver: str, signatures: bytes, tx_sender_private_key: str, tx_gas=None, tx_gas_price=None, block_identifier: Optional[Union[Literal['latest', 'earliest', 'pending'], BlockNumber, Hash32, HexStr, HexBytes, int]] = 'latest') EthereumTxSent

Build and send Safe tx

Parameters
  • to

  • value

  • data

  • operation

  • safe_tx_gas

  • base_gas

  • gas_price

  • gas_token

  • refund_receiver

  • signatures

  • tx_sender_private_key

  • tx_gas – Gas for the external tx. If not, (safe_tx_gas + data_gas) * 2 will be used

  • tx_gas_price – Gas price of the external tx. If not, gas_price will be used

  • block_identifier

Returns

Tuple(tx_hash, tx)

Raises

InvalidMultisigTx: If user tx cannot go through the Safe

class gnosis.safe.safe.SafeCreationEstimate(gas, gas_price, payment, payment_token)

Bases: tuple

gas: int

Alias for field number 0

gas_price: int

Alias for field number 1

payment: int

Alias for field number 2

payment_token: Optional[str]

Alias for field number 3

class gnosis.safe.safe.SafeInfo(address: <function NewType.<locals>.new_type at 0x7fe1df3cab80>, fallback_handler: <function NewType.<locals>.new_type at 0x7fe1df3cab80>, guard: <function NewType.<locals>.new_type at 0x7fe1df3cab80>, master_copy: <function NewType.<locals>.new_type at 0x7fe1df3cab80>, modules: List[ChecksumAddress], nonce: int, owners: List[ChecksumAddress], threshold: int, version: str)

Bases: object

address: ChecksumAddress
fallback_handler: ChecksumAddress
guard: ChecksumAddress
master_copy: ChecksumAddress
modules: List[ChecksumAddress]
nonce: int
owners: List[ChecksumAddress]
threshold: int
version: str
class gnosis.safe.safe.SafeOperation(value)

Bases: Enum

An enumeration.

CALL = 0
CREATE = 2
DELEGATE_CALL = 1

gnosis.safe.safe_create2_tx module

exception gnosis.safe.safe_create2_tx.InvalidERC20Token

Bases: Exception

class gnosis.safe.safe_create2_tx.SafeCreate2Tx(salt_nonce, owners, threshold, fallback_handler, master_copy_address, proxy_factory_address, payment_receiver, payment_token, payment, gas, gas_price, payment_token_eth_value, fixed_creation_cost, safe_address, safe_setup_data)

Bases: tuple

fallback_handler: str

Alias for field number 3

fixed_creation_cost: Optional[int]

Alias for field number 12

gas: int

Alias for field number 9

gas_price: int

Alias for field number 10

master_copy_address: str

Alias for field number 4

owners: List[str]

Alias for field number 1

payment: int

Alias for field number 8

property payment_ether
payment_receiver: str

Alias for field number 6

payment_token: str

Alias for field number 7

payment_token_eth_value: float

Alias for field number 11

proxy_factory_address: str

Alias for field number 5

safe_address: str

Alias for field number 13

safe_setup_data: bytes

Alias for field number 14

salt_nonce: int

Alias for field number 0

threshold: int

Alias for field number 2

class gnosis.safe.safe_create2_tx.SafeCreate2TxBuilder(w3: Web3, master_copy_address: str, proxy_factory_address: str)

Bases: object

build(owners: List[str], threshold: int, salt_nonce: int, gas_price: int, fallback_handler: Optional[str] = None, payment_receiver: Optional[str] = None, payment_token: Optional[str] = None, payment_token_eth_value: float = 1.0, fixed_creation_cost: Optional[int] = None)

Prepare Safe creation :param owners: Owners of the Safe :param threshold: Minimum number of users required to operate the Safe :param fallback_handler: Handler for fallback calls to the Safe :param salt_nonce: Web3 instance :param gas_price: Gas Price :param payment_receiver: Address to refund when the Safe is created. Address(0) if no need to refund :param payment_token: Payment token instead of paying the funder with ether. If None Ether will be used :param payment_token_eth_value: Value of payment token per 1 Ether :param fixed_creation_cost: Fixed creation cost of Safe (Wei)

calculate_create2_address(safe_setup_data: bytes, salt_nonce: int)

gnosis.safe.safe_creation_tx module

exception gnosis.safe.safe_creation_tx.InvalidERC20Token

Bases: Exception

class gnosis.safe.safe_creation_tx.SafeCreationTx(w3: Web3, owners: List[str], threshold: int, signature_s: int, master_copy: str, gas_price: int, funder: Optional[str], payment_token: Optional[str] = None, payment_token_eth_value: float = 1.0, fixed_creation_cost: Optional[int] = None)

Bases: object

static find_valid_random_signature(s: int) Tuple[int, int]

Find v and r valid values for a given s :param s: random value :return: v, r

property payment_ether

gnosis.safe.safe_signature module

exception gnosis.safe.safe_signature.CannotCheckEIP1271ContractSignature

Bases: SafeSignatureException

class gnosis.safe.safe_signature.SafeSignature(signature: Union[bytes, str], safe_tx_hash: Union[bytes, str])

Bases: ABC

export_signature() HexBytes

Exports signature in a format that’s valid individually. That’s important for contract signatures, as it will fix the offset :return:

abstract is_valid(ethereum_client: EthereumClient, safe_address: str) bool
Parameters
  • ethereum_client – Required for Contract Signature and Approved Hash check

  • safe_address – Required for Approved Hash check

Returns

True if signature is valid, False otherwise

abstract property owner
Returns

Decode owner from signature, without any further validation (signature can be not valid)

classmethod parse_signature(signatures: Union[bytes, str], safe_tx_hash: Union[bytes, str], ignore_trailing: bool = True) List[SafeSignature]
Parameters
  • signatures – One or more signatures appended. EIP1271 data at the end is supported.

  • safe_tx_hash

  • ignore_trailing – Ignore trailing data on the signature. Some libraries pad it and add some zeroes at the end

Returns

List of SafeSignatures decoded

abstract property signature_type: SafeSignatureType
class gnosis.safe.safe_signature.SafeSignatureApprovedHash(signature: Union[bytes, str], safe_tx_hash: Union[bytes, str])

Bases: SafeSignature

classmethod build_for_owner(owner: str, safe_tx_hash: str) SafeSignatureApprovedHash
is_valid(ethereum_client: EthereumClient, safe_address: str) bool
Parameters
  • ethereum_client – Required for Contract Signature and Approved Hash check

  • safe_address – Required for Approved Hash check

Returns

True if signature is valid, False otherwise

property owner
Returns

Decode owner from signature, without any further validation (signature can be not valid)

property signature_type
class gnosis.safe.safe_signature.SafeSignatureContract(signature: Union[bytes, str], safe_tx_hash: Union[bytes, str], contract_signature: Union[bytes, str])

Bases: SafeSignature

EIP1271_MAGIC_VALUE = HexBytes('0x20c13b0b')
EIP1271_MAGIC_VALUE_UPDATED = HexBytes('0x1626ba7e')
export_signature() HexBytes

Fix offset (s) and append contract_signature at the end of the signature :return:

is_valid(ethereum_client: EthereumClient, *args) bool
Parameters
  • ethereum_client – Required for Contract Signature and Approved Hash check

  • safe_address – Required for Approved Hash check

Returns

True if signature is valid, False otherwise

property owner: ChecksumAddress
Returns

Address of contract signing. No further checks to get the owner are needed, but it could be a non existing contract

property signature_type: SafeSignatureType
class gnosis.safe.safe_signature.SafeSignatureEOA(signature: Union[bytes, str], safe_tx_hash: Union[bytes, str])

Bases: SafeSignature

is_valid(*args) bool
Parameters
  • ethereum_client – Required for Contract Signature and Approved Hash check

  • safe_address – Required for Approved Hash check

Returns

True if signature is valid, False otherwise

property owner
Returns

Decode owner from signature, without any further validation (signature can be not valid)

property signature_type
class gnosis.safe.safe_signature.SafeSignatureEthSign(signature: Union[bytes, str], safe_tx_hash: Union[bytes, str])

Bases: SafeSignature

is_valid(*args) bool
Parameters
  • ethereum_client – Required for Contract Signature and Approved Hash check

  • safe_address – Required for Approved Hash check

Returns

True if signature is valid, False otherwise

property owner
Returns

Decode owner from signature, without any further validation (signature can be not valid)

property signature_type
exception gnosis.safe.safe_signature.SafeSignatureException

Bases: Exception

class gnosis.safe.safe_signature.SafeSignatureType(value)

Bases: Enum

An enumeration.

APPROVED_HASH = 1
CONTRACT_SIGNATURE = 0
EOA = 2
ETH_SIGN = 3
static from_v(v: int)
gnosis.safe.safe_signature.uint_to_address(value: int) ChecksumAddress

Convert a Solidity uint value to a checksummed address, removing invalid padding bytes if present

Returns

Checksummed address

gnosis.safe.safe_tx module

class gnosis.safe.safe_tx.EIP712LegacySafeTx(**kwargs)

Bases: EIP712Struct

data = <eip712_structs.types.Bytes object>
dataGas = <eip712_structs.types.Uint object>
gasPrice = <eip712_structs.types.Uint object>
gasToken = <eip712_structs.types.Address object>
nonce = <eip712_structs.types.Uint object>
operation = <eip712_structs.types.Uint object>
refundReceiver = <eip712_structs.types.Address object>
safeTxGas = <eip712_structs.types.Uint object>
to = <eip712_structs.types.Address object>
type_name = 'SafeTx'
value = <eip712_structs.types.Uint object>
class gnosis.safe.safe_tx.EIP712SafeTx(**kwargs)

Bases: EIP712Struct

baseGas = <eip712_structs.types.Uint object>
data = <eip712_structs.types.Bytes object>
gasPrice = <eip712_structs.types.Uint object>
gasToken = <eip712_structs.types.Address object>
nonce = <eip712_structs.types.Uint object>
operation = <eip712_structs.types.Uint object>
refundReceiver = <eip712_structs.types.Address object>
safeTxGas = <eip712_structs.types.Uint object>
to = <eip712_structs.types.Address object>
type_name = 'SafeTx'
value = <eip712_structs.types.Uint object>
class gnosis.safe.safe_tx.SafeTx(ethereum_client: EthereumClient, safe_address: str, to: Optional[str], value: int, data: bytes, operation: int, safe_tx_gas: int, base_gas: int, gas_price: int, gas_token: Optional[str], refund_receiver: Optional[str], signatures: Optional[bytes] = None, safe_nonce: Optional[int] = None, safe_version: Optional[str] = None, chain_id: Optional[int] = None)

Bases: object

call(tx_sender_address: Optional[str] = None, tx_gas: Optional[int] = None, block_identifier: Optional[Union[Literal['latest', 'earliest', 'pending'], BlockNumber, Hash32, HexStr, HexBytes, int]] = 'latest') int
Parameters
  • tx_sender_address

  • tx_gas – Force a gas limit

  • block_identifier

Returns

1 if everything ok

property chain_id: int
property contract
property eip712_structured_data: Dict
execute(tx_sender_private_key: str, tx_gas: Optional[int] = None, tx_gas_price: Optional[int] = None, tx_nonce: Optional[int] = None, block_identifier: Optional[Union[Literal['latest', 'earliest', 'pending'], BlockNumber, Hash32, HexStr, HexBytes, int]] = 'latest', eip1559_speed: Optional[TxSpeed] = None) Tuple[HexBytes, TxParams]

Send multisig tx to the Safe

Parameters
  • tx_sender_private_key – Sender private key

  • tx_gas – Gas for the external tx. If not, (safe_tx_gas + base_gas) * 2 will be used

  • tx_gas_price – Gas price of the external tx. If not, gas_price will be used

  • tx_nonce – Force nonce for tx_sender

  • block_identifierlatest or pending

  • eip1559_speed – If provided, use EIP1559 transaction

Returns

Tuple(tx_hash, tx)

Raises

InvalidMultisigTx: If user tx cannot go through the Safe

recommended_gas() Wei
Returns

Recommended gas to use on the ethereum_tx

property safe_nonce: str
property safe_tx_hash: HexBytes
property safe_version: str
sign(private_key: str) bytes

{bytes32 r}{bytes32 s}{uint8 v} :param private_key: :return: Signature

property signers: List[str]
property sorted_signers
tx: TxParams
tx_hash: bytes
unsign(address: str) bool
property w3
property w3_tx
Returns

Web3 contract tx prepared for call, transact or buildTransaction

gnosis.safe.serializers module

class gnosis.safe.serializers.SafeMultisigEstimateTxSerializer(*args, **kwargs)

Bases: Serializer

validate(data)
validate_operation(value)
class gnosis.safe.serializers.SafeMultisigTxSerializer(*args, **kwargs)

Bases: SafeMultisigEstimateTxSerializer

DEPRECATED, use SafeMultisigTxSerializerV1 instead

class gnosis.safe.serializers.SafeMultisigTxSerializerV1(*args, **kwargs)

Bases: SafeMultisigEstimateTxSerializer

Version 1.0.0 of the Safe changes data_gas to base_gas

class gnosis.safe.serializers.SafeSignatureSerializer(*args, **kwargs)

Bases: Serializer

When using safe signatures v can have more values

check_r(r)
check_s(s)
check_v(v)
validate(data)
validate_v(v)

gnosis.safe.signatures module

gnosis.safe.signatures.get_signing_address(signed_hash: Union[bytes, str], v: int, r: int, s: int) str
Returns

checksummed ethereum address, for example 0x568c93675A8dEb121700A6FAdDdfE7DFAb66Ae4A

Return type

str or NULL_ADDRESS if signature is not valid

gnosis.safe.signatures.signature_split(signatures: Union[bytes, str], pos: int = 0) Tuple[int, int, int]
Parameters
  • signatures – signatures in form of {bytes32 r}{bytes32 s}{uint8 v}

  • pos – position of the signature

Returns

Tuple with v, r, s

gnosis.safe.signatures.signature_to_bytes(v: int, r: int, s: int) bytes

Convert ecdsa signature to bytes :param v: :param r: :param s: :return: signature in form of {bytes32 r}{bytes32 s}{uint8 v}

gnosis.safe.signatures.signatures_to_bytes(signatures: List[Tuple[int, int, int]]) bytes

Convert signatures to bytes :param signatures: list of tuples(v, r, s) :return: 65 bytes per signature

Module contents