ape-safe


Nameape-safe JSON
Version 0.8.12 PyPI version JSON
download
home_pagehttps://github.com/ApeWorX/ape-safe
Summaryape-safe: Gnosis Safe account plugin for Ape
upload_time2025-07-14 19:44:06
maintainerNone
docs_urlNone
authorApeWorX Ltd.
requires_python<4,>=3.9
licenseApache-2.0
keywords ethereum
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Quick Start

Account plugin for the [Safe](https://safe.global//) Multisig wallet (previously known as Gnosis Safe).

## Dependencies

- [python3](https://www.python.org/downloads) version 3.9 up to 3.12.

## Installation

### via `ape`

You can install using the [ape](https://github.com/ApeWorX/ape) built-in plugin manager:

```bash
$ ape plugins install safe
```

### via `pip`

You can install the latest release via [`pip`](https://pypi.org/project/pip/):

```bash
$ pip install ape-safe
```

### via `setuptools`

You can clone the repository and use [`setuptools`](https://github.com/pypa/setuptools) for the most up-to-date version:

```bash
$ git clone https://github.com/ApeWorX/ape-safe.git
$ cd ape-safe
$ python3 setup.py install
```

## Quick Usage

To use the plugin, first use the CLI extension to add a safe you created:

```sh
ape safe add --network ethereum:mainnet "my-safe.eth" my-safe
```

If you made a mistake or just need to remove the safe, use the `remove` command:

```sh
ape safe remove my-safe --yes
```

**NOTE** `--yes` is a way to skip the prompt.

If you only add one safe, you will not have to specify which safe to use other commands.
Otherwise, for most `pending` commands, you specify the safe to use (by alias) via the `--safe` option.

Additionally, you can configure a safe to use as the default in your `ape-config.yaml` file:

```yaml
safe:
  default_safe: my-safe
```

or via `pyproject.toml`:

```toml
[tool.ape.safe]
default_safe = "my-safe"
```

To specify via environment variable, do:

```sh
APE_SAFE_DEFAULT_SAFE="my-safe"
```

**NOTE**: Also, to avoid always needing to specify `--network`, you can set a default ecosystem, network, and provider in your config file.
The rest of the guide with not specify `--network` on each command but assume the correct one is set in the config file.
Here is an example:

```yaml
default_ecosystem: optimism

ethereum:
  default_network: sepolia
  sepolia:
    default_provider: infura
```

Once you have a safe, you can view pending transactions:

```sh
ape safe pending list
```

```{note}
You must specify the environment variable `APE_SAFE_GATEWAY_API_KEY=` to use the Safe Gateway API.
Get an API key at https://developer.safe.global/.
```

It should show transactions like this:

```sh
Transaction 8 rejection (1/2) safe_tx_hash=0x09ab9a229fc60da66ec0fa8fa886ab7c95902fdf5df5a5009ba06010fbb9a9a7
Transaction 8 transfer  (1/2) safe_tx_hash=0xed43d80255bcd5ffacb755e8f51bee825913373705d6baea006419d2a33a0a5b
```

**NOTE**: Use the `--verbose` flag to see more information about each transaction.

```sh
ape safe pending list --verbose
```

There are several operations you can do on a pending transaction.
One of them is "approve" which adds your local signers' signatures to the transaction.

```sh
ape safe pending approve 0x09ab9a229fc60da66ec0fa8fa886ab7c95902fdf5df5a5009ba06010fbb9a9a7
```

**NOTE**: Here we are using the transaction hash `0x09ab9a229fc60da66ec0fa8fa886ab7c95902fdf5df5a5009ba06010fbb9a9a7` to specify the transaction because there are more than one.
However, you can also use the nonce if there is only a single transaction.

If you want to both execute and approve at the same time, you can use the `--execute` option on approve and specify a sender:

```sh
ape safe pending approve 2 --execute my_account
```

Else, you can use the `execute` command directly:

```sh
ape safe pending execute 2
```

**NOTE**: `execute` requires a full signed transaction ready to be submitted on-chain.

The last main operation is `reject`.
Rejecting a transaction replaces that transaction with a zero-value transfer from the safe to itself.

```sh
ape safe pending reject 2
```

### Multisend

The following example shows how to use multisend:

```python
from ape_safe import multisend
from ape import accounts
from ape_tokens import tokens

safe = accounts.load("my-safe")

# Load some contracts (here using ape-tokens)
dai = tokens["DAI"]
vault = tokens["yvDAI"]
amount = dai.balanceOf(safe)  # How much we want to deposit

# Create a multisend transaction (a transaction that executes multiple calls)
txn = multisend.MultiSend()
txn.add(dai.approve, vault, amount)
txn.add(vault.deposit, amount)

# Fetch signatures from any local signers, and broadcast if confirmations are met
# Note that in case the user intends to only stage a transaction, then `submit=False` argument can also be added
# It is normal that when a user only intend to stage a transaction, an error is thrown
# this can be ignored by including the necessary try-catch (from ape.exceptions import SignatureError)
# Note that transaction is automatically prompted for execution if enough signers are available in local
txn(sender=safe,gas=0)
```

## Cloud Usage

To use this plugin in a cloud environment, such as with the [Silverback Platform](https://silverback.apeworx.io), you will need to make sure that you have configured your Safe to exist within the environment.
The easiest way to do this is to use the `require` configuration item.
To specify a required Safe in your `ape-config.yaml` (which adds it into your `~/.ape/safe` folder if it doesn't exist), use:

```yaml
safe:
  require:
    my-safe:
      address: "0x1234...AbCd"
      deployed_chain_ids: [1, ...]
```

or in `pyproject.toml`:

```toml
[tool.ape.safe.require."my-safe"]
address = "0x1234...AbCd"
deployed_chain_ids = [1, ...]
```

To specify via environment variable, do:

```sh
APE_SAFE_REQUIRE='{"my-safe":{"address":"0x1234...AbCd","deployed_chain_ids":[1,...]}}'
```

```{notice}
If a safe with the same alias as an entry in `require` exists in your local environment, this will skip adding it, even if the existing alias points to a different address than the one in the config item.
```

## Development

Please see the [contributing guide](CONTRIBUTING.md) to learn more how to contribute to this project.
Comments, questions, criticisms and pull requests are welcomed.

## Acknowledgements

This package was inspired by [the original ape-safe](https://github.com/banteg/ape-safe#readme) by [banteg](https://github.com/banteg).
For versions prior to v0.6.0, the original package should be referenced.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ApeWorX/ape-safe",
    "name": "ape-safe",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.9",
    "maintainer_email": null,
    "keywords": "ethereum",
    "author": "ApeWorX Ltd.",
    "author_email": "admin@apeworx.io",
    "download_url": "https://files.pythonhosted.org/packages/bf/5a/92dca112640736af2c10913a15b5972a8795fb1011ca12ce718f0ee708ff/ape_safe-0.8.12.tar.gz",
    "platform": null,
    "description": "# Quick Start\n\nAccount plugin for the [Safe](https://safe.global//) Multisig wallet (previously known as Gnosis Safe).\n\n## Dependencies\n\n- [python3](https://www.python.org/downloads) version 3.9 up to 3.12.\n\n## Installation\n\n### via `ape`\n\nYou can install using the [ape](https://github.com/ApeWorX/ape) built-in plugin manager:\n\n```bash\n$ ape plugins install safe\n```\n\n### via `pip`\n\nYou can install the latest release via [`pip`](https://pypi.org/project/pip/):\n\n```bash\n$ pip install ape-safe\n```\n\n### via `setuptools`\n\nYou can clone the repository and use [`setuptools`](https://github.com/pypa/setuptools) for the most up-to-date version:\n\n```bash\n$ git clone https://github.com/ApeWorX/ape-safe.git\n$ cd ape-safe\n$ python3 setup.py install\n```\n\n## Quick Usage\n\nTo use the plugin, first use the CLI extension to add a safe you created:\n\n```sh\nape safe add --network ethereum:mainnet \"my-safe.eth\" my-safe\n```\n\nIf you made a mistake or just need to remove the safe, use the `remove` command:\n\n```sh\nape safe remove my-safe --yes\n```\n\n**NOTE** `--yes` is a way to skip the prompt.\n\nIf you only add one safe, you will not have to specify which safe to use other commands.\nOtherwise, for most `pending` commands, you specify the safe to use (by alias) via the `--safe` option.\n\nAdditionally, you can configure a safe to use as the default in your `ape-config.yaml` file:\n\n```yaml\nsafe:\n  default_safe: my-safe\n```\n\nor via `pyproject.toml`:\n\n```toml\n[tool.ape.safe]\ndefault_safe = \"my-safe\"\n```\n\nTo specify via environment variable, do:\n\n```sh\nAPE_SAFE_DEFAULT_SAFE=\"my-safe\"\n```\n\n**NOTE**: Also, to avoid always needing to specify `--network`, you can set a default ecosystem, network, and provider in your config file.\nThe rest of the guide with not specify `--network` on each command but assume the correct one is set in the config file.\nHere is an example:\n\n```yaml\ndefault_ecosystem: optimism\n\nethereum:\n  default_network: sepolia\n  sepolia:\n    default_provider: infura\n```\n\nOnce you have a safe, you can view pending transactions:\n\n```sh\nape safe pending list\n```\n\n```{note}\nYou must specify the environment variable `APE_SAFE_GATEWAY_API_KEY=` to use the Safe Gateway API.\nGet an API key at https://developer.safe.global/.\n```\n\nIt should show transactions like this:\n\n```sh\nTransaction 8 rejection (1/2) safe_tx_hash=0x09ab9a229fc60da66ec0fa8fa886ab7c95902fdf5df5a5009ba06010fbb9a9a7\nTransaction 8 transfer  (1/2) safe_tx_hash=0xed43d80255bcd5ffacb755e8f51bee825913373705d6baea006419d2a33a0a5b\n```\n\n**NOTE**: Use the `--verbose` flag to see more information about each transaction.\n\n```sh\nape safe pending list --verbose\n```\n\nThere are several operations you can do on a pending transaction.\nOne of them is \"approve\" which adds your local signers' signatures to the transaction.\n\n```sh\nape safe pending approve 0x09ab9a229fc60da66ec0fa8fa886ab7c95902fdf5df5a5009ba06010fbb9a9a7\n```\n\n**NOTE**: Here we are using the transaction hash `0x09ab9a229fc60da66ec0fa8fa886ab7c95902fdf5df5a5009ba06010fbb9a9a7` to specify the transaction because there are more than one.\nHowever, you can also use the nonce if there is only a single transaction.\n\nIf you want to both execute and approve at the same time, you can use the `--execute` option on approve and specify a sender:\n\n```sh\nape safe pending approve 2 --execute my_account\n```\n\nElse, you can use the `execute` command directly:\n\n```sh\nape safe pending execute 2\n```\n\n**NOTE**: `execute` requires a full signed transaction ready to be submitted on-chain.\n\nThe last main operation is `reject`.\nRejecting a transaction replaces that transaction with a zero-value transfer from the safe to itself.\n\n```sh\nape safe pending reject 2\n```\n\n### Multisend\n\nThe following example shows how to use multisend:\n\n```python\nfrom ape_safe import multisend\nfrom ape import accounts\nfrom ape_tokens import tokens\n\nsafe = accounts.load(\"my-safe\")\n\n# Load some contracts (here using ape-tokens)\ndai = tokens[\"DAI\"]\nvault = tokens[\"yvDAI\"]\namount = dai.balanceOf(safe)  # How much we want to deposit\n\n# Create a multisend transaction (a transaction that executes multiple calls)\ntxn = multisend.MultiSend()\ntxn.add(dai.approve, vault, amount)\ntxn.add(vault.deposit, amount)\n\n# Fetch signatures from any local signers, and broadcast if confirmations are met\n# Note that in case the user intends to only stage a transaction, then `submit=False` argument can also be added\n# It is normal that when a user only intend to stage a transaction, an error is thrown\n# this can be ignored by including the necessary try-catch (from ape.exceptions import SignatureError)\n# Note that transaction is automatically prompted for execution if enough signers are available in local\ntxn(sender=safe,gas=0)\n```\n\n## Cloud Usage\n\nTo use this plugin in a cloud environment, such as with the [Silverback Platform](https://silverback.apeworx.io), you will need to make sure that you have configured your Safe to exist within the environment.\nThe easiest way to do this is to use the `require` configuration item.\nTo specify a required Safe in your `ape-config.yaml` (which adds it into your `~/.ape/safe` folder if it doesn't exist), use:\n\n```yaml\nsafe:\n  require:\n    my-safe:\n      address: \"0x1234...AbCd\"\n      deployed_chain_ids: [1, ...]\n```\n\nor in `pyproject.toml`:\n\n```toml\n[tool.ape.safe.require.\"my-safe\"]\naddress = \"0x1234...AbCd\"\ndeployed_chain_ids = [1, ...]\n```\n\nTo specify via environment variable, do:\n\n```sh\nAPE_SAFE_REQUIRE='{\"my-safe\":{\"address\":\"0x1234...AbCd\",\"deployed_chain_ids\":[1,...]}}'\n```\n\n```{notice}\nIf a safe with the same alias as an entry in `require` exists in your local environment, this will skip adding it, even if the existing alias points to a different address than the one in the config item.\n```\n\n## Development\n\nPlease see the [contributing guide](CONTRIBUTING.md) to learn more how to contribute to this project.\nComments, questions, criticisms and pull requests are welcomed.\n\n## Acknowledgements\n\nThis package was inspired by [the original ape-safe](https://github.com/banteg/ape-safe#readme) by [banteg](https://github.com/banteg).\nFor versions prior to v0.6.0, the original package should be referenced.\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "ape-safe: Gnosis Safe account plugin for Ape",
    "version": "0.8.12",
    "project_urls": {
        "Homepage": "https://github.com/ApeWorX/ape-safe"
    },
    "split_keywords": [
        "ethereum"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c3d09436f24e1a43ae146d855f386641d64d2178292fcbeda5cb3e3628842281",
                "md5": "2f0c9e1dec138bb1f76f12feba398b49",
                "sha256": "71fce62455c343e5a80a78c4da263170e079100f884874eb9c0efa1a444f6665"
            },
            "downloads": -1,
            "filename": "ape_safe-0.8.12-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2f0c9e1dec138bb1f76f12feba398b49",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4,>=3.9",
            "size": 234908,
            "upload_time": "2025-07-14T19:44:04",
            "upload_time_iso_8601": "2025-07-14T19:44:04.886351Z",
            "url": "https://files.pythonhosted.org/packages/c3/d0/9436f24e1a43ae146d855f386641d64d2178292fcbeda5cb3e3628842281/ape_safe-0.8.12-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bf5a92dca112640736af2c10913a15b5972a8795fb1011ca12ce718f0ee708ff",
                "md5": "3cd595765139ccb8d17d21506fa09a72",
                "sha256": "a3a483f951284beb1c7a30670e1a13b65141b6605fb3a0a2ced44a753ebd7fa4"
            },
            "downloads": -1,
            "filename": "ape_safe-0.8.12.tar.gz",
            "has_sig": false,
            "md5_digest": "3cd595765139ccb8d17d21506fa09a72",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.9",
            "size": 292180,
            "upload_time": "2025-07-14T19:44:06",
            "upload_time_iso_8601": "2025-07-14T19:44:06.472909Z",
            "url": "https://files.pythonhosted.org/packages/bf/5a/92dca112640736af2c10913a15b5972a8795fb1011ca12ce718f0ee708ff/ape_safe-0.8.12.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-14 19:44:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ApeWorX",
    "github_project": "ape-safe",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "ape-safe"
}
        
Elapsed time: 0.45253s