• Stars
    star
    138
  • Rank 264,508 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created about 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Command line utility for Gnosis Safe

PyPI version Build Status Coverage Status Python 3.9 Python 3.10

Safe-CLI

Command line utility for Safe contracts. Use it to manage your Safe easily from the command line

Using with docker

If you have Docker installed on your system, you can just run:

docker run -it safeglobal/safe-cli safe-creator

for creating Safes

or

docker run -it safeglobal/safe-cli safe-cli

to run the actual safe-cli

Installing

Python >= 3.7 is required. Python 3.10 is recommended.

pip3 install -U safe-cli

Using

safe-cli <checksummed_safe_address> <ethereum_node_url>

Then you should be on the prompt and see information about the Safe, like the owners, version, etc. Next step would be loading some owners for the Safe. At least threshold owners need to be loaded to do operations on the Safe and at least one of them should have funds for sending transactions.

There're 3 operation modes:

  • blockchain: The default mode, transactions are sent to blockchain.
  • tx-service: Use tx-service command to enable it. Transactions are sent to the Gnosis Transaction Service (if available on the network), so you will be able to see it on the Safe web interface/mobile apps. At least one signer is needed to send transactions to the service. Txs are not executed.
  • relay-service: Use relay-service [optional-gas-token] to enable it. Sends transactions trough the Gnosis Relay Service (if available on the network). If a optional gas token is set, it will be used to send transactions.

Loading owners is not needed if you just want to do read-only operations.

To load owners:

> load_cli_owners <account_private_key>
Loaded account 0xab...cd with balance=123 ether
Set account 0xab..cd as default sender of txs

You can also load owners from an environment variable. Before running the safe-cli:

export MY_PRIVATE_KEY=YOUR_EOA_PRIVATE_KEY

Then:

> load_cli_owners MY_PRIVATE_KEY
Loaded account 0xab...cd with balance=123 ether
Set account 0xab..cd as default sender of txs

To check the loaded owners:

> show_cli_owners

To unload an owner:

> unload_cli_owners <ethereum_checksummed_address>

Operations currently supported:

  • send_custom <address> <value-wei> <data-hex-str> [--delegate] [--safe-nonce <int>]: Sends a custom transaction from the Safe to a contract. If --delegate is set a delegatecall will be triggered.
  • send_ether <address> <value-wei> [--safe-nonce <int>]: Sends ether from the Safe to another account
  • send_erc20 <address> <token_address> <value> [--safe-nonce <int>]: Send ERC20 token from the Safe to another account
  • approve_hash <keccak-hexstr-hash> <sender-address>: Approves a safe-tx-hash for the provided sender address. Sender private key must be loaded first.
  • add_owner <address>: Adds a new owner address to the Safe.
  • remove_owner <address>: Removes an owner address from the Safe.
  • change_threshold <integer>: Changes the threshold of the Safe.
  • enable_module <address>: Enable module address
  • disable_module <address>: Disable module address
  • change_fallback_handler <address>: Updates the fallback handler to be address. Supported by Safes with version >= v1.1.0. WARNING: DON'T USE THIS IF YOU DON'T KNOW WHAT YOU ARE DOING. ALL YOUR FUNDS COULD BE LOST
  • change_guard <address>: Updates the guard to be address. Supported by Safes with version >= v1.3.0. WARNING: DON'T USE THIS IF YOU DON'T KNOW WHAT YOU ARE DOING. ALL YOUR FUNDS COULD BE LOST
  • change_master_copy <address>: Updates the master copy to be address. It's used to update the Safe. WARNING: DON'T USE THIS IF YOU DON'T KNOW WHAT YOU ARE DOING. ALL YOUR FUNDS COULD BE LOST
  • update: Updates the Safe to the latest version (if you are on a known network like Goerli or Mainnet). WARNING: DON'T USE THIS IF YOU DON'T KNOW WHAT YOU ARE DOING. ALL YOUR FUNDS COULD BE LOST

Operations on tx-service mode, requires a Safe Transaction Service working on the network (Mainnet, Gnosis Chain, Goerli, Polygon...):

  • balances: Returns a list of balances for ERC20 tokens and ether.
  • history: History of multisig transactions (including pending).
  • execute-tx <safe-tx-hash>: Execute a pending tx with enough signatures.
  • sign-tx <safe-tx-hash>: Sign a tx with the loaded owners for the provided SafeTxHash.
  • batch-txs <safe-nonce> <safe-tx-hash> [ <safe-tx-hash> ... ]: Batch transactions into one Multisig Transaction using the provided safe-nonce. Any safe-tx can be used: transactions from other Safes, transactions already executed, transactions pending for execution... Only limitation is that
  • transactions from other networks cannot be used. Batching order will follow the same order of the safe-tx-hashes provided.
  • get_delegates: Returns a list of delegates for the Safe.
  • add_delegate <address> <label> <signer-address>: Adds a new delegate address to the Safe.
  • remove_delegate <address> <signer-address>: Removes a delegate address from the Safe.
  • drain <address>: Sends all ether and ERC20 funds to the provided account.

If the information in the information bar is outdated or there's any problem you can force the safe-cli to update the information about the Safe using:

> refresh

Creating a new Safe

Use safe-creator <node_url> <private_key> --owners <checksummed_address_1> <checksummed_address_2> --threshold <uint> --salt-nonce <uint256>.

Example:

safe-creator https://goerli.infura.io/v3/token $PRIVATE_KEY --owners 0x848EF06Bb9d1bc79Bb3B04b7Ea0e251C6E788d7c --threshold 1

Demo

For this demo, PRIVATE_KEY environment variable was set to a EOA private key (owner of a a previously created and outdated Safe) and ETHEREUM_NODE_URL to a http goerli node. At first, Safe is updated to the last version and then 123 Wei are sent to the owner of the Safe (it could be any other address).

Be careful when using update command, as it can leave your Safe funds stuck. Safe CLI is still a beta

asciicast

Use custom contracts

Safe-cli comes with the official Safe contract addresses deployed on Mainnet, Rinkeby, Kovan and Goerli configured by default. If you want to use your own you can edit the file safe_cli/safe_addresses.py

Be careful when modifying these addresses, the funds in a Safe can get stuck if an invalid address it's used when updating to an invalid Safe Master Copy.

Safe contracts

Setting up for developing

If you miss something and want to send us a PR:

git clone https://github.com/gnosis/safe-cli.git
cd safe-cli
stat venv 2>/dev/null || python3 -m venv venv
source venv/bin/activate && pip install -r requirements-dev.txt
pre-commit install -f

Contributors

More Repositories

1

safe-smart-account

Safe allows secure management of blockchain assets.
TypeScript
1,827
star
2

safe-wallet-web

Safe{Wallet} – multisig EVM wallet
TypeScript
352
star
3

safe-apps-sdk

Client-side SDKs to create third-party Safe Apps
TypeScript
205
star
4

safe-core-sdk

The Safe{Core} Account Abstraction SDK allows builders to add account abstraction functionality into their apps.
TypeScript
202
star
5

safe-transaction-service

Keeps track of transactions sent via Safe contacts and confirmed transactions. It also keeps track of Ether and ERC20 token transfers to Safe contracts.
Python
184
star
6

safe-modules

A collection of modules that can be used with the Safe contract
TypeScript
140
star
7

safe-deployments

A collection of Safe singleton deployments
TypeScript
131
star
8

safe-eth-py

Safe-eth-py includes a set of libraries to work with Ethereum and relevant Ethereum projects
Python
118
star
9

safe-ios

Safe Multisig iOS app.
Swift
114
star
10

safe-react-apps

A repository for applications for Safe Web Interface
TypeScript
99
star
11

safe-android

🔐 App to manage and interact with Safe
Kotlin
90
star
12

safe-singleton-factory

Singleton factory used by Safe related contracts
TypeScript
77
star
13

safe-docs

Developer Docs for building on Safe.
MDX
51
star
14

safe-react-components

Gnosis Safe component library
TypeScript
35
star
15

safe-user-allocation-reports

Python
34
star
16

account-abstraction-sdk

TypeScript
31
star
17

safe-config-service

The safe-config-service is a service that provides configuration information in the context of the Safe clients environment
Python
31
star
18

safe-client-gateway

Serves as a bridge for the Safe{Wallet} clients (Android, iOS, Web)
TypeScript
23
star
19

safe-gateway-typescript-sdk

Safe Gateway TypeScript SDK
TypeScript
20
star
20

safe-token

TypeScript
19
star
21

safe-infrastructure

One `docker-compose.yml` file to rule them all
Shell
19
star
22

safe-modules-deployments

This repo contains a collection of deployments of audited contracts from the Safe modules repository.
TypeScript
9
star
23

safe-ecosystem-database

Safe ecosystem database
HTML
6
star
24

safe-homepage

Safe homepage
TypeScript
6
star
25

safe-gelato-relay-service

The Safe Gelato Relay Service is a web service which allows relaying transactions via the Gelato Relay Service.
TypeScript
6
star
26

safe-services-status

📈 Uptime monitor and status page for Safe, powered by @upptime
Markdown
5
star
27

claiming-app-data

Vesting data converter and proofs generator.
Python
5
star
28

safe-dao-governance-app

The portal to Safe{DAO} governance, voting power delegation and allocation claiming.
TypeScript
3
star
29

safe-pm

Production coordination for the Safe team primarily focused on Problems that need to be solved
2
star
30

safe-locking

Safe Token Locking Contracts
TypeScript
2
star
31

safe-guardians-page

This page is dedicated to the Safe Guardians program, a program designed to reward active members of the Safe community, who use their powers to contribute positively to the ecosystem.
TypeScript
2
star
32

safecon-landing-page

Safe{Con} landing page
CSS
1
star
33

cla-signatures

CLA signatures repository
1
star
34

token-list

This repo contain the Safe default token list. This list contains tokens which appear by default in the Safe wallet interface and are not part of the imported default token lists.
Shell
1
star