Skip to content
Projets

À propos

Command line utility for Safe

Outils de développement

Comment ces chiffres sont mesurés

Progression mesurée des étoiles

in 24h
0
in 7 days
-1
in 15 days
-1
in 1 month
Historique en cours

Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.

README.md

Original

PyPI version Build Status Coverage Status Python 3.11 Python 3.12 Python 3.13 Python 3.14 Container image

Safe CLI

Safe CLI is a command-line utility for Safe contracts. You can use it to manage your Safe account from the command line.

It does not rely on Safe{Core} API and can also be used in networks where Safe services are unavailable. Learn more through the documentation.

The package installs two commands:

Using Docker

Prerequisite: Install Docker Desktop.

Run the Safe CLI with an existing Safe:

docker run --rm -it ghcr.io/safe-global/safe-cli safe-cli <checksummed_safe_address> <ethereum_node_url>

Create a new Safe:

docker run --rm -it ghcr.io/safe-global/safe-cli safe-creator <ethereum_node_url> <deployer_private_key>

The Docker image does not include Ledger and Trezor support. To use a hardware wallet, install Safe CLI with uv.

Using uv

Prerequisite: Python >= 3.11 (Python 3.13 is recommended) and uv.

Install Safe CLI:

uv tool install safe-cli

Ledger and Trezor support are optional extras. Remove the one you do not need:

uv tool install "safe-cli[ledger,trezor]"

Safe CLI

Wherever a private key is expected, you can pass the name of an environment variable that holds it. This keeps keys out of the shell history.

Interactive mode

safe-cli <safe_address> <node_url> [--history] [--get-safes-from-owner]
Option Description
--history Save the command history to a .history file in the directory of the safe-cli script. Disabled by default for security reasons, as commands can include private keys.
--get-safes-from-owner address is an owner, not a Safe. The CLI lists the Safes of that owner and asks you to pick one. Needs the Safe Transaction Service.

Example:

safe-cli 0x0000000000000000000000000000000000000000 https://sepolia.drpc.org --history

Inside the prompt, use Tab to complete commands, help to list them, and exit (or Ctrl+D) to quit.

Blockchain and tx-service modes

The prompt starts in blockchain mode. Type tx-service to switch to tx-service mode and blockchain to switch back. The prompt shows the current mode.

Blockchain mode Tx-service mode
Signatures The loaded owners must reach the Safe threshold. Partial signatures are allowed. Loaded delegates can also sign.
Result The transaction is executed on-chain, paid by the first loaded owner with balance. The transaction is proposed to the Safe Transaction Service, so other owners can sign it.
Network Any network with a node url. Only networks supported by the Safe Transaction Service.

Switching to tx-service mode starts with no private keys loaded, so load them again. Hardware wallets stay loaded.

To use tx-service mode, set your API key. You can get one from https://developer.safe.global.

export SAFE_TRANSACTION_SERVICE_API_KEY=your_api_key_here

Load owners

Commands that send a transaction need the owners loaded first.

Command Description
load_cli_owners <private_key> [<private_key>...] Load owners from private keys.
load_cli_owners_from_words <word_1> ... <word_n> Load owners from a BIP39 seed phrase. It checks the first 100 accounts (m/44'/60'/0'/0/i) and loads only the Safe owners. A single word is read as the name of an environment variable that holds the seed phrase.
load_ledger_cli_owners / load_trezor_cli_owners [--derivation-path <path>] [--legacy-accounts] Load an owner from a Ledger or a Trezor. Needs the ledger or trezor extra. Without --derivation-path, it shows 5 accounts to pick from, using 44'/60'/{i}'/0/0 for Ledger and 44'/60'/0'/0/{i} for Trezor. --legacy-accounts uses 44'/60'/0'/{i} for both.
unload_cli_owners <address> [<address>...] Unload owners.
show_cli_owners Show the loaded owners and the sender of the transactions.

Read Safe information

Command Description
info Show the Safe information: owners, threshold, nonce, version, modules, guard, fallback handler, balance.
refresh Reload the Safe information from the chain.
get_owners, get_threshold, get_nonce Read one value from the chain.

Send assets

Command Description
send_ether <to> <value_wei> Send ETH.
send_erc20 <to> <token_address> <amount> Send ERC20 tokens. amount is in the smallest token unit.
send_erc721 <to> <token_address> <token_id> Send an ERC721 token.
send_custom <to> <value_wei> <data> [--delegate] Send a transaction with custom data. --delegate uses DELEGATECALL instead of CALL.
drain <to> Send all ETH and ERC20 tokens of the Safe to <to> in one MultiSend transaction.

All send_* commands accept --safe-nonce <int>. By default the current Safe nonce is used.

Manage the Safe

Command Description
add_owner <address> [--threshold <int>] Add an owner and optionally change the threshold.
remove_owner <address> [--threshold <int>] Remove an owner and optionally change the threshold.
change_threshold <int> Change the threshold.
enable_module <address> / disable_module <address> Enable or disable a module.
change_fallback_handler <address> Change the fallback handler. Safe >= 1.1.0.
change_guard <address> Change the transaction guard. Safe >= 1.3.0.
change_module_guard <address> Change the module guard. Safe >= 1.5.0.
approve_hash <safe_tx_hash> <sender> Approve a Safe transaction hash on-chain from an owner loaded from a private key. Blockchain mode only.

A wrong guard or fallback handler can lock the Safe. Check the contract before you set it.

Upgrade the Safe

Command Description
update Update the master copy and the fallback handler to the latest version. Safe < 1.3.0 only.
change_master_copy <address> Change the master copy. Safe < 1.3.0 only.
update_version_to_l2 <migration_contract_address> Migrate a Safe to the L2 version of the master copy, using the Safe migration contract. Safe 1.1.1, 1.3.0 or 1.4.1 with nonce 0 only.

Sign messages

Command Description
sign_message --eip191_message Sign an EIP-191 message. The CLI asks for the message text.
sign_message --eip712_path <file> Sign an EIP-712 message from a JSON file.
confirm_message <safe_message_hash> <signer_address> Add a signature to a message in the Safe Transaction Service. Tx-service mode only.

In blockchain mode, sign_message sends an on-chain transaction to SignMessageLib. In tx-service mode, it proposes an off-chain message to the Safe Transaction Service.

Tx-service mode commands

Command Description
balances Show ETH and token balances.
history Show the executed and queued transactions.
sign-tx <safe_tx_hash> Sign a proposed transaction with the loaded owners and delegates.
execute-tx <safe_tx_hash> Execute a proposed transaction on-chain.
batch-txs <safe_nonce> <safe_tx_hash> [<safe_tx_hash>...] Join proposed transactions into one MultiSend transaction with the given nonce and propose it.
remove_proposed_transaction <safe_tx_hash> Remove a proposed transaction. The proposer must be loaded.
get_delegates List the delegates of the Safe.
add_delegate <address> <label> <signer_address> Add a delegate. The signer must be an owner loaded from a private key.
remove_delegate <address> <signer_address> Remove a delegate. The signer must be an owner loaded from a private key.

Unattended mode

These commands run one transaction and exit. They work in blockchain mode only: the private keys must reach the Safe threshold.

safe-cli <command> <safe_address> <node_url> <arguments> --private-key <key> [--private-key <key>...] [options]
Command Arguments Description
send-ether <to> <value_wei> Send ETH.
send-erc20 <to> <token_address> <amount> Send ERC20 tokens. amount is in the smallest token unit.
send-erc721 <to> <token_address> <token_id> Send an ERC721 token.
send-custom <to> <value_wei> <data> Send a transaction with custom data. Add --delegate to use DELEGATECALL instead of CALL.
tx-builder <file_path> Send the transactions of a JSON file exported from the Transaction Builder Safe App. Several transactions are sent as one MultiSend transaction.
Option Description
--private-key Private key of a signer. Required, repeat it for each signer.
--safe-nonce <int> Set the Safe nonce of the transaction. Not available for tx-builder.
--non-interactive Do not ask for confirmation. Use it in scripts. You can also set SAFE_CLI_INTERACTIVE=0.

safe-cli version prints the version. Use --help on each command to see all its options, for example safe-cli send-ether --help.

Example:

export OWNER_1_KEY=0x...
export OWNER_2_KEY=0x...
safe-cli send-ether 0x0000000000000000000000000000000000000000 https://sepolia.drpc.org 0x0000000000000000000000000000000000000001 1000000000000000 \
  --private-key OWNER_1_KEY --private-key OWNER_2_KEY --non-interactive

Safe Creator

safe-creator <node_url> <deployer_private_key> [options]
Option Default Description
--owners <address> [<address>...] The deployer Owners of the Safe.
--threshold <int> 1 Number of owners required to execute transactions.
--salt-nonce <int> Random Salt nonce for the deployment. The same nonce with the same options gives the same Safe address.
--safe-contract <address> SafeL2 1.4.1 (1.3.0 if 1.4.1 is not deployed) Custom Safe master copy.
--without-events Off Use the non-L2 Safe master copy, which saves gas on mainnet. No effect when --safe-contract is set.
--callback-handler <address> 1.4.1 (1.3.0 if 1.4.1 is not deployed) Custom fallback handler.
--proxy-factory <address> 1.4.1 (1.3.0 if 1.4.1 is not deployed) Custom proxy factory.
--generate-vanity-addresses Off Do not deploy, only print addresses. See below.
--no-confirm Off Do not ask for confirmation.
-v, --version Print the version.

Run safe-creator --help to see all the options.

Generate vanity addresses

safe-creator https://sepolia.drpc.org $PRIVATE_KEY --generate-vanity-addresses --no-confirm

It prints one <safe_address> <salt_nonce> line for each salt nonce from 0 up, until you press Ctrl+C. The address depends on all the other options, so use the same options as the real deployment. Then deploy the address you like with --salt-nonce <salt_nonce>.

Safe{Core} API/Protocol

Development

git clone https://github.com/safe-global/safe-cli.git
cd safe-cli
uv sync --frozen --group dev --all-extras
uv run --frozen pre-commit install -f

To run safe-cli or safe-creator from the repository:

uv run --frozen safe-cli <safe_address> <node_url>
uv run --frozen safe-creator <node_url> <private_key>

Running the tests

The tests need a local anvil node on http://localhost:8545. run_tests.sh starts anvil with Docker Compose, runs the tests and stops anvil:

./run_tests.sh

To run some tests many times, start anvil once and keep it running:

docker compose --profile develop up --detach --wait anvil
uv run --frozen pytest tests/test_safe_operator.py
docker compose --profile develop down

Set ETHEREUM_NODE_URL to use another node.

Contributors

Explorer des projets similaires

Chargement…