Skip to content

5afe/safe-cli-nodejs

Repository files navigation

πŸ” Safe CLI npm version

A modern, interactive command-line tool for managing Safe Smart Accounts

Built on top of the Safe Core SDK, Safe CLI makes it easy to create, manage, and interact with Safe multi-signature wallets directly from your terminal.


Why Safe CLI?

Safe CLI provides a powerful command-line interface for:

  • Creating and managing Safe accounts without using the web interface
  • Coordinating multi-signature transactions with your team
  • Interacting with smart contracts through an intuitive transaction builder
  • Automating Safe operations in scripts and workflows
  • Managing multiple Safes across different chains from one place
  • Hardware wallet support - Use Ledger devices for maximum security

Perfect for developers, power users, and teams who prefer working in the terminal.


✨ Features

Core Functionality

  • πŸ” Secure wallet management - Encrypted private key storage with AES-256-GCM + Ledger hardware wallet support
  • ⛓️ Multi-chain support - Works with Ethereum, Polygon, Arbitrum, Optimism, Base, and more
  • 🎨 Beautiful interface - Modern terminal UI with interactive prompts
  • πŸ“¦ Safe lifecycle - Create, deploy, and manage Safe accounts
  • πŸ“ Transaction handling - Create, sign, and execute transactions

Advanced Features

  • πŸ€– Smart contract interaction - Automatic ABI fetching and interactive function builder
  • πŸ”Œ Proxy support - Detects and handles EIP-1967 proxy contracts
  • πŸ‘₯ Owner management - Add/remove owners and change thresholds
  • πŸ”„ Multi-sig coordination - Multiple workflows for collecting signatures
  • πŸ“₯ Transaction import - Import from Safe web app's Transaction Builder

πŸš€ Quick Start

Installation

# Install globally
npm install -g @safe-global/safe-cli

# Or run without installing
npx @safe-global/safe-cli

First-Time Setup

1. Initialize configuration

safe config init

This sets up your chain configurations and optional API keys.

2. Set up a wallet

# Option A: Create a new wallet (generates private key)
safe wallet create

# Option B: Import existing private key
safe wallet import

# Option C: Import Ledger hardware wallet (recommended for production)
safe wallet import-ledger

Private keys are encrypted with a password. Ledger wallets use your hardware device for signing.

3. Create your first Safe

safe account create

Follow the interactive prompts to configure owners and threshold.

That's it! You're ready to manage Safe accounts from your terminal.


πŸ“š Command Reference

Configuration

Command Description
safe config init Set up CLI for first use (includes API keys)
safe config show View current configuration
safe config chains list List configured networks
safe config chains add Add a custom network
safe config chains remove Remove a network
safe config chains edit Edit chains in your text editor

Wallets

Command Description
safe wallet create Create a new wallet with a generated private key
safe wallet import Import a wallet with your existing private key
safe wallet import-ledger Import a Ledger hardware wallet
safe wallet list View all your wallets (shows wallet types)
safe wallet use Switch to a different wallet
safe wallet remove Delete a wallet

Safe Accounts

Command Description
safe account create Create a new Safe
safe account deploy [address] Deploy a predicted Safe to the blockchain
safe account open [address] Add an existing Safe to your workspace
safe account list View all your Safes
safe account info [address] Show Safe details (owners, threshold, balance)
safe account add-owner [address] Add a new owner
safe account remove-owner [address] Remove an owner
safe account change-threshold [address] Change signature threshold

πŸ’‘ Tip: Most commands support EIP-3770 format (eth:0x123...) or will prompt you interactively.

Transactions

Command Description
safe tx create Create a new transaction
safe tx sign [txHash] Sign a transaction
safe tx execute [txHash] Execute a transaction
safe tx list View transactions
safe tx status [txHash] Check signature progress
safe tx export [txHash] Export as JSON for sharing
safe tx import [json] Import from JSON

Multi-sig Coordination:

Command Description
safe tx push [txHash] Upload to Safe Transaction Service
safe tx pull Download pending transactions
safe tx sync Sync local and remote transactions

πŸ’‘ Common Workflows

Creating and Deploying a Safe

# 1. Create a Safe (gets predicted address)
safe account create

# 2. Deploy it to the blockchain
safe account deploy eth:0x742d35Cc...

Sending ETH from a Safe

# Create and sign a transaction
safe tx create
# β†’ Select your Safe
# β†’ Enter recipient address
# β†’ Enter amount in wei
# β†’ Sign it

# If you're the only signer needed, execute immediately
safe tx execute <txHash>

# Or, share the transaction with other signers (see Multi-sig section)

Interacting with a Smart Contract

safe tx create
# β†’ Select your Safe
# β†’ Enter contract address

# The CLI automatically:
# βœ“ Detects it's a contract
# βœ“ Fetches the ABI from Etherscan/Sourcify
# βœ“ Shows you all available functions
# βœ“ Helps you fill in parameters with validation
# βœ“ Encodes the transaction

# Then sign and execute as usual

Multi-sig Coordination

Option A: Using Safe Transaction Service (Recommended)

# Owner 1: Create and push
safe tx create
safe tx sign <txHash>
safe tx push <txHash>

# Owner 2: Pull and sign
safe tx pull
safe tx sign <txHash>
safe tx push <txHash>

# Any owner: Execute when threshold is met
safe tx execute <txHash>

Option B: Offline with JSON Export

# Owner 1: Create and export
safe tx create
safe tx sign <txHash>
safe tx export <txHash>
# β†’ Share the JSON with other owners

# Owner 2: Import and sign
safe tx import '{"safeTxHash":"0x..."...}'
safe tx sign <txHash>

# Check progress
safe tx status <txHash>  # Shows "2/3 signatures"

# Execute when ready
safe tx execute <txHash>

βš™οΈ Configuration

Storage Location

Configuration files are stored in:

  • macOS: ~/Library/Preferences/safe-cli/
  • Linux: ~/.config/safe-cli/
  • Windows: %APPDATA%\safe-cli\

Supported Networks (Default)

Pre-configured for 18+ networks including:

  • Ethereum, Sepolia (testnet)
  • Layer 2s: Arbitrum, Optimism, Base, Polygon, zkSync Era, Polygon zkEVM, Scroll, Linea
  • Alternative L1s: BNB Chain, Gnosis Chain, Avalanche, Celo, Aurora
  • Emerging chains: Mantle, World Chain, Sonic, Unichain

Add custom networks with safe config chains add.

Optional API Keys

These are optional but recommended for enhanced functionality:

Safe Transaction Service API Key

Get it from: Safe Developer Dashboard

Enables:

  • Multi-sig coordination via Safe Transaction Service
  • Push/pull transactions
  • Integration with Safe web interface

Without it: You can still use offline JSON export/import for multi-sig.

Etherscan API Key

Get it from: Etherscan (free)

Enables:

  • Proxy contract detection (EIP-1967)
  • Better ABI fetching for proxies
  • Automatic ABI merging for proxy + implementation

Without it: Uses Sourcify as fallback (still works, but no proxy detection).

Setup: Run safe config init and follow the prompts, or edit the config file manually.


πŸ” Security

Private Key Wallets

  • Key generation: Uses Node.js crypto.randomBytes() for cryptographically secure random generation
  • Encryption: Private keys encrypted with AES-256-GCM
  • Key derivation: PBKDF2 with 100,000 iterations
  • Local storage: All data stored locally on your machine
  • No exposure: Keys never logged or transmitted in plain text
  • Backup verification: Confirmation required when creating new wallets

Hardware Wallets (Ledger)

  • Maximum security: Private keys never leave the device
  • Physical confirmation: All transactions require on-device approval
  • Industry standard: BIP44 derivation paths
  • Secure Element: Military-grade chip protection

Recommendation: Use Ledger hardware wallets for production Safe accounts with significant funds.


πŸ› οΈ For Developers

Prerequisites

  • Node.js >= 18.0.0
  • npm or yarn

Development Setup

# Clone the repository
git clone https://github.com/5afe/safe-cli-nodejs.git
cd safe-cli-nodejs

# Install dependencies
npm install

# Run in development mode
npm run dev

# Type checking
npm run typecheck

# Run tests
npm test

# Build
npm run build

Project Structure

src/
β”œβ”€β”€ commands/           # Command implementations
β”‚   β”œβ”€β”€ config/        # Configuration commands
β”‚   β”œβ”€β”€ wallet/        # Wallet management (incl. Ledger)
β”‚   β”œβ”€β”€ account/       # Safe account operations
β”‚   └── tx/            # Transaction commands
β”œβ”€β”€ services/          # Business logic
β”‚   β”œβ”€β”€ safe-service.ts
β”‚   β”œβ”€β”€ transaction-service.ts
β”‚   β”œβ”€β”€ ledger-service.ts      # Ledger hardware wallet integration
β”‚   β”œβ”€β”€ abi-service.ts
β”‚   └── validation-service.ts
β”œβ”€β”€ storage/           # Persistent storage
β”‚   β”œβ”€β”€ config-store.ts
β”‚   β”œβ”€β”€ wallet-store.ts
β”‚   └── transaction-store.ts
β”œβ”€β”€ ui/                # Terminal UI components (React/Ink)
β”œβ”€β”€ types/             # TypeScript type definitions
└── utils/             # Utility functions

Tech Stack

  • TypeScript - Type safety
  • Commander.js - CLI framework
  • React + Ink - Terminal UI
  • @clack/prompts - Interactive prompts
  • Viem - Ethereum utilities
  • Safe Core SDK - Safe protocol integration
  • LedgerJS - Hardware wallet integration
  • Zod - Runtime validation

🀝 Contributing

Contributions are welcome! Here's how:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests (npm test)
  5. Commit with a clear message
  6. Push and open a Pull Request

Please ensure:

  • Tests pass (npm test)
  • TypeScript compiles (npm run typecheck)
  • Code is formatted (npm run format)

πŸ“– Additional Resources


πŸ“„ License

LGPL-3.0


Made with ❀️ for the Safe community

About

Safe CLI (Node.js)

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •