Package: web3cli
Interact with blockchains and smart contracts using the command line: no coding needed!Table of contentsFeaturesInstallSimple examplesAdvanced examplesSmart Contract supportRead from a smart contractSend a transaction to a smart contractMulti-chain supportUse custom RPCAdd custom chainsAddress bookWallet managementDefault signerCreate new private keysDocumentationContributingAcknowledgementsFeaturesInteract with Ethereum and EVM-compatible chains via your terminalBypass sluggish and potentially compromised frontendsNo configuration neededLabel addresses, tokens and contracts for ease of useSwap with Uniswap, TraderJoe, PancakeSwap, etcSupport for the Compound V2 lending protocol and its forks (e.g. Eralend)Transfer tokens via their tickerSet Telegram alerts based on pending transactions, new blocks and contract eventsReplay transactions just with the tx hashConcatenate commands to build powerful scriptsImport signers via private key or keyfileThoroughly tested using theApe Framework's testing frameworkWindows compatibleSoon:React to pending transactions, new blocks and contract eventsSet up scheduled buys and sells (DCA)Automatically buy when slippage is low enoughGet notified on Telegram when a pair is liquid enough, or unbalancedAnalyze on-chain data for tax or sleuthing purposesClaim and reinvest yield from DeFi protocolsInstallMake sure you have at least Python 3.9 installed, then run:pip3install-Uweb3cliThe same command will also upgrade web3cli to the latest version.Windows user?Here's a tutorial for you!Install via pipxFan of isolated environments?  Install web3cli viapipx:pipxinstallweb3cliTo upgrade web3cli, runpipx upgrade web3cli.Simple examplesGet the ETH balance of any address:w3 balance 0xde0b295669a9fd93d5f28d9ec85e40f4cb697baeSave addresses with easy-to-rember tags:w3 address add unicef 0xa59b29d7dbc9794d1e7f45123c48b2b8d0a34636then use the tag in any command:w3 balance unicefFetch blocks from the blockchain, in easy-to-read JSON format:w3blocklatest
w3blockfinalized
w3block6094305Fetch transactions & receipts from the blockchain:w3txget0x3bbdcc2c7721521f7c767b7873ccb857f0816ac94e9f32c5601f4b15c87d1ef1
w3txrc0x3bbdcc2c7721521f7c767b7873ccb857f0816ac94e9f32c5601f4b15c87d1ef1Extract single fields from blocks or transactions, usingjq(more detailsin the Wiki):w3blocklatest|jq-r'.baseFeePerGas'Sign messages:w3sign'Hello world!'Get Keccak256 hashes starting from a text or a hex-string:w3keccak-text'Hello world!'w3keccak-hex'b495b1154ef1b2'Advanced examplesSend coins or tokens to any address:w3 send unicef 1 ETH      # send 1 ETH, ask for confirmation
w3 send unicef 1 ETH gwei # send 1 gwei, ask for confirmation
w3 send unicef 1 usdc     # send 1 USDCSwap tokens on a DEX:w3 swap uniswap_v2 1 usdc usdt     # swap 1 USDC for USDT on Uniswap
w3avax swap traderjoe 1 usdc wavax # swap 1 USDC for WAVAX on TraderJoeStream blocks, transactions and contract events as they happen in realtime:w3 subscribe blocks   # stream blocks as they are mined
w3 subscribe pending  # stream pending transactions
w3 subscribe events   # stream all contract eventsStreaming requires a websocket connection: specify one with the--rpc wss://...flag.Set a Telegram alert for when a specific event is emitted:# Get notified on Telegram when USDC is transferredtransfer=0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
w3subscribeevents--telegram--contractsusdc--topics$transfer# Send a post notification when USDC is transferredw3subscribeevents--posthttps://www.example.com/--contractsusdc--topics$transferTelegram alerts require setting up a Telegram bot, please find instructionsin the Wiki.Replay a given transactions on the blockchain:tx=`w3sendunicef1USDC--force`# send 1 USDC to Unicefw3replay$tx# re-send 1 USDC to UnicefSmart Contract supportweb3cli comes preloaded with some popular smart contracts, including ERC20 tokens and Uniswap clones.See the available contracts withw3 contract list:w3 contract list               # contracts on Ethereum
w3 contract list --chain bnb   # contracts on BNB chain
w3 contract list --type erc20  # tokens on EthereumYou can also add custom contracts withw3 contract add:w3 contract add weth 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 --type erc20
w3 contract add sushi 0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F --type uniswap_v2To add or list new tokens, you can use thew3 tokenshorthand:w3 token add weth 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
w3 token list
w3 token delete wethSee available functions and events on a contract withw3 abi functionsandw3 abi events:w3 abi fns weth           # functions on WETH token
w3 abi evs uniswap_v2     # events on Uniswap V2
w3 abi fns --abi abi.json # functions of an arbitrary ABIRead from a smart contractTo read from a smart contract, usew3 call. For example, to get the total
supply of the WETH token, run:w3 call weth totalSupplyFunction arguments are parsed automatically, so you can callbalanceOfwith:w3 call weth balanceOf 0xA59B29d7dbC9794d1e7f45123C48b2b8d0a34636You can also do more complex stuff like:# get the amount of USDT you get for 100 USDCw3calluniswap_v2getAmountsOut100e6usdc,usdt|jq-r'.[1]'Send a transaction to a smart contractTo write to the blockchain, usew3 transact. For example, to transfer 1 ETH to
address, run:w3 transact weth transfer <address> 1e18To swap 1 USDC for USDT on Uniswap, accepting no less than 0.9 USDT in return, run:w3 transact usdc approve uniswap_v2 1e6
w3 transact uniswap_v2 swapExactTokensForTokens 1e6 0.9e6 usdc,usdt <receiver address> 9e9Multi-chain supportweb3cli comes with out-of-the-box support for many chains.  To see the list of available chains,visit the Wikior run the commandw3 chain list.Pass the chain name using the flag--chainor the shorthand-c:w3 balance 0x8894e0a0c962cb723c1976a4421c95949be2d4e3 --chain bnb  # bnb chain
w3 balance 0x8894e0a0c962cb723c1976a4421c95949be2d4e3 --chain avax # avax chainYou can also use one of the provided aliases, likew3bnb,w3avax, orw3arb:w3bnb balance 0x8894e0a0c962cb723c1976a4421c95949be2d4e3  # bnb chain
w3avax balance 0x8894e0a0c962cb723c1976a4421c95949be2d4e3 # avax chainIf you are focussing on a specific chain, set it as the default:w3 config set default_chain bnb
w3 balance 0x8894e0a0c962cb723c1976a4421c95949be2d4e3             # bnb chain
w3 balance 0x8894e0a0c962cb723c1976a4421c95949be2d4e3 --chain eth # eth chainUse custom RPCBy default, web3cli will connect to the blockchain using a pre-configured public node.  You can see the list of such nodes with the commandw3 rpc list.To use a custom mode, please specify the--rpcflag.  For example, to use Ankr's node to Ethereum:w3blocklatest--rpchttps://rpc.ankr.com/ethUsing a custom node is most useful in the following situations:You want to use a node from a node provider, e.g. Infura:w3block--rpchttps://eth-mainnet.g.alchemy.com/v2/{YOUR-API-KEY}You want to use a private node:w3block--rpchttp://127.0.0.1:8545
w3block--rpcws://127.0.0.1:8546You want to use a testnet chain:w3ethblock--rpchttps://rpc.ankr.com/eth_goerli
w3bnbblock--rpchttps://data-seed-prebsc-1-s1.binance.org:8545/Add custom chainsAdd new chains withw3 chain add:w3 chain add cronos 25 CRO --tx-type 2 --rpc https://evm.cronos.orgUse the custom chain with--chain:w3 balance 0x7de9ab1e6a60ac7a70ce96d1d95a0dfcecf7bfb7 --chain cronosList existing chains withw3 chain list, and delete them withw3 chain delete.Address bookw3can store tags just like you would do on etherscan.io or bscscan.com:w3addressaddethereum_foundation0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae
w3addressaddbinance_hot_wallet0x8894e0a0c962cb723c1976a4421c95949be2d4e3You can use these tags instead of the actual addresses:w3balanceethereum_foundation
w3balancebinance_hot_wallet--chainbnbTo see the list of saved addresses, runw3 address list, to delete an address usew3 address delete.Wallet managementCommands such asw3 sendandw3 swaprequire that you specify who is going to sign the transactions.  You can specify the signer with the--signeror-sflag:w3<command>--signermy-signerHere,my_signercan be any of these things:The name or the address of a signer that you previously registered withw3 signer add my_signer.  Signers created in this way are encrypted with the app key and stored in the database.  At any time, you can see the list of registered users by runningw3 signer list.The path to a file that you previously created withw3 keyfile create.  A keyfile is a simple JSON file that contains your private key in password-encrypted form.  Feel free to use keyfiles generated by other tools, like geth, parity, brownie, etc.The actual private key of the signer that you want to use.  This is unsafe, use it at your own risk!Please note that when the--signerflag is not provided, and there is only one registered signer, then this will be used.Default signerIf you plan to use the same signer for a while, make it thedefault signerwith the command:w3configsetdefault_signermy_signerIn this way, you will not have to specify the--signerflag anymore.Create new private keysYou can also create a brand new wallet on the go, without the need to provide a key, by using the--createflag:w3signeraddmy_wallet--createThe resulting private key will be printed to screen.DocumentationCheck theproject's wiki on Github. In particular:🫡 List of commands⛓ All supported chains📝 Configuration🪟 Run web3cli on Windows↪️ Output processingContributingAll contributions are welcome! To start improving web3cli, please refer to ourcontribution guide.AcknowledgementsThank you very much to the communities behindweb3.pyand theApe Framework: web3cli would not exist without your efforts!