Skip to content

Commit

Permalink
Adding support for executing transactions in scripting mode (#419)
Browse files Browse the repository at this point in the history
* Add send_ether command

* Add send_custom, send_erc20 and send_erc721 commands

* Add tx_builder command

* Add support for env keys

* Add test to tx_builder_decoder

* Update Readme

* Fix encoding of tuple type

* Merge safe-cli and safe-runner

* Apply PR suggestions

* Revert tx_builder command

* Update feedback messages to user.

* Improve default command validation

* Add interactive/no-interactive option

* Update common parameters
  • Loading branch information
falvaradorodriguez authored Jun 26, 2024
1 parent a9427b2 commit ddd66d6
Show file tree
Hide file tree
Showing 10 changed files with 1,033 additions and 292 deletions.
93 changes: 86 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,92 @@ pip3 install -U safe-cli

## Usage

### Safe-Cli

```bash
usage:
safe-cli [--history] [--get-safes-from-owner] address node_url

Examples:
safe-cli 0x0000000000000000000000000000000000000000 https://sepolia.drpc.org
safe-cli --get-safes-from-owner 0x0000000000000000000000000000000000000000 https://sepolia.drpc.org

safe-cli --history 0x0000000000000000000000000000000000000000 https://sepolia.drpc.org
safe-cli --history --get-safes-from-owner 0x0000000000000000000000000000000000000000 https://sepolia.drpc.org

safe-cli send-ether 0xsafeaddress https://sepolia.drpc.org 0xtoaddress wei-amount --private-key key1 --private-key key1 --private-key keyN
safe-cli send-erc721 0xsafeaddress https://sepolia.drpc.org 0xtoaddress 0xtokenaddres id --private-key key1 --private-key key2 --private-key keyN
safe-cli send-erc20 0xsafeaddress https://sepolia.drpc.org 0xtoaddress 0xtokenaddres wei-amount --private-key key1 --private-key key2 --private-key keyN
safe-cli send-custom 0xsafeaddress https://sepolia.drpc.org 0xtoaddress value 0xtxdata --private-key key1 --private-key key2 --private-key keyN

╭─ Arguments ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
* address CHECKSUMADDRESS The address of the Safe, or an owner address if --get-safes-from-owner is specified. [required] │
* node_url TEXT Ethereum node url. [required] │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --help Show this message and exit. │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Optional Arguments ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --history --no-history Enable history. By default it's disabled due to security reasons [default: no-history] │
│ --get-safes-from-owner --no-get-safes-from-owner Indicates that address is an owner (Safe Transaction Service is required for this feature) [default: no-get-safes-from-owner] │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Commands available in unattended mode:
send-ether
send-erc20
send-erc721
send-custom
version
Use the --help option of each command to see the usage options.
```
To execute transactions unattended you can use:
```bash
safe-cli send-ether 0xsafeaddress https://sepolia.drpc.org 0xtoaddress wei-amount --private-key key1 --private-key key1 --private-key keyN --non-interactive
safe-cli send-erc721 0xsafeaddress https://sepolia.drpc.org 0xtoaddress 0xtokenaddres id --private-key key1 --private-key key2 --private-key keyN --non-interactive
safe-cli send-erc20 0xsafeaddress https://sepolia.drpc.org 0xtoaddress 0xtokenaddres wei-amount --private-key key1 --private-key key2 --private-key keyN --non-interactive
safe-cli send-custom 0xsafeaddress https://sepolia.drpc.org 0xtoaddress value 0xtxdata --private-key key1 --private-key key2 --private-key keyN --non-interactive
```
It is possible to use the environment variable `SAFE_CLI_INTERACTIVE=0` to avoid user interactions. The `--non-interactive` option have more priority than environment variable.
### Safe-Creator
```bash
safe-cli [-h] [--history] [--get-safes-from-owner] address node_url
usage:
safe-creator [-h] [-v] [--threshold THRESHOLD] [--owners OWNERS [OWNERS ...]] [--safe-contract SAFE_CONTRACT] [--proxy-factory PROXY_FACTORY] [--callback-handler CALLBACK_HANDLER] [--salt-nonce SALT_NONCE] [--without-events] node_url private_key
Example:
safe-creator https://sepolia.drpc.org 0000000000000000000000000000000000000000000000000000000000000000
positional arguments:
address The address of the Safe, or an owner address if --get-safes-from-owner is specified.
node_url Ethereum node url
node_url Ethereum node url
private_key Deployer private_key
options:
-h, --help Show this help message and exit
--history Enable history. By default it's disabled due to security reasons
--get-safes-from-owner Indicates that address is an owner (Safe Transaction Service is required for this feature)
```
-h, --help show this help message and exit
-v, --version Show program's version number and exit.
--threshold THRESHOLD
Number of owners required to execute transactions on the created Safe. It mustbe greater than 0 and less or equal than the number of owners
--owners OWNERS [OWNERS ...]
Owners. By default it will be just the deployer
--safe-contract SAFE_CONTRACT
Use a custom Safe master copy
--proxy-factory PROXY_FACTORY
Use a custom proxy factory
--callback-handler CALLBACK_HANDLER
Use a custom fallback handler. It is not required for Safe Master Copies with version < 1.1.0
--salt-nonce SALT_NONCE
Use a custom nonce for the deployment. Same nonce with same deployment configuration will lead to the same Safe address
--without-events Use non events deployment of the Safe instead of the regular one. Recommended for mainnet to save gas costs when using the Safe


```
## Safe{Core} API/Protocol
Expand All @@ -72,6 +145,12 @@ source venv/bin/activate && pip install -r requirements-dev.txt
pre-commit install -f
```
To run the local version you can install it using:
```bash
pip install .
```
## Contributors
- [Pedro Arias Ruiz](https://github.com/AsiganTheSunk)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ requests==2.32.3
safe-eth-py==6.0.0b30
tabulate==0.9.0
trezor==0.13.8
typer==0.12.3
web3==6.19.0
Loading

0 comments on commit ddd66d6

Please sign in to comment.