A python Ethereum utilities command-line tool.

Related tags

CLI Tools peth
Overview

peth-cli

A python Ethereum utilities command-line tool.

After wasting the all day trying to install seth and failed, I took another day to write this. :(

Ugly code but works :)

Wish the meta universe peth peace !

Usage

[Optional] Use your own config.json.

& // Do NOT forget the '?' or '&' in the URL. ], ... }">
{
    "eth": [ // Network name
        "https://rpc.ankr.com/eth",      // RPC endpoint URL.
        "https://api.etherscan.io/api?"  // Etherscan-style API URL.

    // Get better experience if you have an API key.
    // https://api.etherscan.io/api?apikey=
   
    &
    
    // Do NOT forget the '?' or '&' in the URL.
    ],

    ...

}

   

RPC

# Basic RPC call.
➜  peth-cli python peth.py  -r eth_blockNumber
0xd80830

# -c to change network.
➜  peth-cli python peth.py  -r eth_blockNumber -c bsc
0xe58858

# RPC call with arguments.
➜  peth-cli python peth.py  -r eth_getBalance 0x0000000000000000000000000000000000000000 latest 
0x2679ce59cfe4a16dd4e

# Raw style.
➜  peth-cli python peth.py  --rpc-call-raw eth_getBlockByNumber '["0x0", false]'                             
{'jsonrpc': '2.0', 'id': 1, 'result': {'difficulty': '0x400000000', 'extraData': '0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa', 'gasLimit': '0x1388', 'gasUsed': '0x0', 'hash': '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3', 'logsBloom': '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', 'miner': '0x0000000000000000000000000000000000000000', 'mixHash': '0x0000000000000000000000000000000000000000000000000000000000000000', 'nonce': '0x0000000000000042', 'number': '0x0', 'parentHash': '0x0000000000000000000000000000000000000000000000000000000000000000', 'receiptsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', 'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', 'size': '0x21c', 'stateRoot': '0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544', 'timestamp': '0x0', 'totalDifficulty': '0x400000000', 'transactions': [], 'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', 'uncles': []}}

Contract call

Human-readable ABI in peth is like:

  • function name (argment type, [...]) -> (return value type, [...])
(string)" Tether USD # Without return type, we get raw hex data. ➜ peth-cli python main.py --to 0xdac17f958d2ee523a2206206994597c13d831ec7 -e "name()" 0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a5465746865722055534400000000000000000000000000000000000000000000 # When only function name provided, peth will try to auto-extract ABI via the Etherscan API. ➜ peth-cli python main.py --to 0xdac17f958d2ee523a2206206994597c13d831ec7 -e name Tether USD ➜ peth-cli python main.py --to 0xdac17f958d2ee523a2206206994597c13d831ec7 -e decimals 6 # Call with arguments ➜ peth-cli python main.py --to 0xdac17f958d2ee523a2206206994597c13d831ec7 -e balanceOf 0xdAC17F958D2ee523a2206206994597C13d831ec7 644096679570">
# Call name() of USDT contract.
➜  peth-cli python main.py --to 0xdac17f958d2ee523a2206206994597c13d831ec7 -e "name()->(string)"
Tether USD

# Without return type, we get raw hex data.
➜  peth-cli python main.py --to 0xdac17f958d2ee523a2206206994597c13d831ec7 -e "name()"
0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a5465746865722055534400000000000000000000000000000000000000000000

# When only function name provided, peth will try to auto-extract ABI via the Etherscan API.
➜  peth-cli python main.py --to 0xdac17f958d2ee523a2206206994597c13d831ec7 -e name                                                
Tether USD
➜  peth-cli python main.py --to 0xdac17f958d2ee523a2206206994597c13d831ec7 -e decimals                                            
6

# Call with arguments
➜  peth-cli python main.py --to 0xdac17f958d2ee523a2206206994597c13d831ec7 -e balanceOf 0xdAC17F958D2ee523a2206206994597C13d831ec7
644096679570

console

erc20 0xdAC17F958D2ee523a2206206994597C13D831ec7 totalSupply() -> (uint256) => 39823315849942740 name() -> (string) => Tether USD symbol() -> (string) => USDT decimals() -> (uint8) => 6 peth > erc20 0xdAC17F958D2ee523a2206206994597C13D831ec7 balanceOf 0xdAC17F958D2ee523a2206206994597C13D831ec7 644096679570 peth > exit bye!">
➜  peth-cli python main.py --console
Welcome to the peth shell.   Type help or ? to list commands.
 
peth > ?

Documented commands (type help 
   
    ):
========================================
balance  bye  contract  erc20  exit  help  nonce  number  quit  storage

peth > number
14158806
peth > balance 0xdAC17F958D2ee523a2206206994597C13D831ec7
1 Wei( 0.0000 Ether)
peth > nonce 0xdAC17F958D2ee523a2206206994597C13D831ec7
1
peth > storage 0xdAC17F958D2ee523a2206206994597C13D831ec7 1
0x000000000000000000000000000000000000000000000000008d7b18430396d4
peth > contract 0xdAC17F958D2ee523a2206206994597C13D831ec7
  SourceCode :   pragma solidity ^0.4.17;
  ABI :  [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string ...
  ContractName :         TetherToken
  CompilerVersion :      v0.4.18+commit.9cf6e910
  OptimizationUsed :     0
  Runs :         0
  ConstructorArguments :         000000000000000000000000000000000000000000000000000000174876e8000000000000000000 ...
  EVMVersion :   Default
  Library :      
  LicenseType :  
  Proxy :        0
  Implementation :       
  SwarmSource :  bzzr://645ee12d73db47fd78ba77fa1f824c3c8f9184061b3b10386beb4dc9236abb28
  === ABI ===
  function name() returns(string ) view
  function deprecate(address _upgradedAddress) returns() nonpayable
  function approve(address _spender,uint256 _value) returns() nonpayable
  function deprecated() returns(bool ) view
  function addBlackList(address _evilUser) returns() nonpayable
  function totalSupply() returns(uint256 ) view
  function transferFrom(address _from,address _to,uint256 _value) returns() nonpayable
  function upgradedAddress() returns(address ) view
  function balances(address ) returns(uint256 ) view
  function decimals() returns(uint256 ) view
  function maximumFee() returns(uint256 ) view
  function _totalSupply() returns(uint256 ) view
  function unpause() returns() nonpayable
  function getBlackListStatus(address _maker) returns(bool ) view
  function allowed(address ,address ) returns(uint256 ) view
  function paused() returns(bool ) view
  function balanceOf(address who) returns(uint256 ) view
  function pause() returns() nonpayable
  function getOwner() returns(address ) view
  function owner() returns(address ) view
  function symbol() returns(string ) view
  function transfer(address _to,uint256 _value) returns() nonpayable
  function setParams(uint256 newBasisPoints,uint256 newMaxFee) returns() nonpayable
  function issue(uint256 amount) returns() nonpayable
  function redeem(uint256 amount) returns() nonpayable
  function allowance(address _owner,address _spender) returns(uint256 remaining) view
  function basisPointsRate() returns(uint256 ) view
  function isBlackListed(address ) returns(bool ) view
  function removeBlackList(address _clearedUser) returns() nonpayable
  function MAX_UINT() returns(uint256 ) view
  function transferOwnership(address newOwner) returns() nonpayable
  function destroyBlackFunds(address _blackListedUser) returns() nonpayable
  constructor (uint256 _initialSupply,string _name,string _symbol,uint256 _decimals) nonpayable
  event Issue(uint256 amount) 
  event Redeem(uint256 amount) 
  event Deprecate(address newAddress) 
  event Params(uint256 feeBasisPoints,uint256 maxFee) 
  event DestroyedBlackFunds(address _blackListedUser,uint256 _balance) 
  event AddedBlackList(address _user) 
  event RemovedBlackList(address _user) 
  event Approval(address owner,address spender,uint256 value) 
  event Transfer(address from,address to,uint256 value) 
  event Pause() 
  event Unpause() 
peth > erc20 0xdAC17F958D2ee523a2206206994597C13D831ec7
totalSupply() -> (uint256) => 39823315849942740
name() -> (string) => Tether USD
symbol() -> (string) => USDT
decimals() -> (uint8) => 6
peth > erc20 0xdAC17F958D2ee523a2206206994597C13D831ec7 balanceOf 0xdAC17F958D2ee523a2206206994597C13D831ec7
644096679570
peth > exit
bye!

   
You might also like...
A command line tool (and Python library) for archiving Twitter JSON

A command line tool (and Python library) for archiving Twitter JSON

Unofficial Open Corporates CLI: OpenCorporates is a website that shares data on corporations under the copyleft Open Database License. This is an unofficial open corporates python command line tool.
Unofficial Open Corporates CLI: OpenCorporates is a website that shares data on corporations under the copyleft Open Database License. This is an unofficial open corporates python command line tool.

Unofficial Open Corporates CLI OpenCorporates is a website that shares data on corporations under the copyleft Open Database License. This is an unoff

Professor Wordlist is a free open source command line tool written in python

Professor Wordlist is a free open source command line tool written in python, With the aim of generating custom wordlists with a variety of unique parameters and functions providing many possibilities.

A simple command line tool written in python to manage a to-do list

A simple command line tool written in python to manage a to-do list Dependencies: python Commands: todolist (-a | --add) [(-p | --priority)] [(-l | --

A command line tool made in Python for the popular rhythm game
A command line tool made in Python for the popular rhythm game

osr!name A command line tool made in Python for the popular rhythm game "osu!" that changes the player name of a .osr file (replay file). Example: Not

spotifytools is a Python command line tool

spotifytools spotifytools is a Python command line tool Documentation The documentation is available on the following link Releases Instalation instru

A command line tool to query source code from your current Python env
A command line tool to query source code from your current Python env

wxc wxc (pronounced "which") allows you to inspect source code in your Python environment from the command line. It is based on the inspect module fro

MsfMania is a command line tool developed in Python that is designed to bypass antivirus software on Windows and Linux/Mac in the future
MsfMania is a command line tool developed in Python that is designed to bypass antivirus software on Windows and Linux/Mac in the future

MsfMania MsfMania is a command line tool developed in Python that is designed to bypass antivirus software on Windows and Linux/Mac in the future. Sum

Bonjour Software pypahe is a Python Package Helper command-line tool.

pypahe Bonjour Software pypahe is a Python Package Helper command-line tool. Requirements Docker runtime Usage print the latest available version of a

Comments
  • bug:

    bug:

    When I download the source code for contract(https://bscscan.com/address/0x9059f2f644402db18155b7917762823a58962397) at BSC, it throws an error:

    Error:  [Errno 13] Permission denied: '/Users'
    Traceback (most recent call last):
      File "/home/learner/tools/anaconda3/envs/slither/lib/python3.10/site-packages/peth-0.1.3-py3.10.egg/peth/core/console.py", line 58, in onecmd
        return super().onecmd(line)
      File "/home/learner/tools/anaconda3/envs/slither/lib/python3.10/cmd.py", line 217, in onecmd
        return func(arg)
      File "/home/learner/tools/anaconda3/envs/slither/lib/python3.10/site-packages/peth-0.1.3-py3.10.egg/peth/core/console.py", line 1331, in do_download_source
        ret = self.peth.scan.download_source(addr, output_dir)
      File "/home/learner/tools/anaconda3/envs/slither/lib/python3.10/site-packages/peth-0.1.3-py3.10.egg/peth/eth/scan.py", line 193, in download_source
        os.makedirs(parent_dir)
      File "/home/learner/tools/anaconda3/envs/slither/lib/python3.10/os.py", line 215, in makedirs
        makedirs(head, exist_ok=exist_ok)
      File "/home/learner/tools/anaconda3/envs/slither/lib/python3.10/os.py", line 215, in makedirs
        makedirs(head, exist_ok=exist_ok)
      File "/home/learner/tools/anaconda3/envs/slither/lib/python3.10/os.py", line 215, in makedirs
        makedirs(head, exist_ok=exist_ok)
      [Previous line repeated 3 more times]
      File "/home/learner/tools/anaconda3/envs/slither/lib/python3.10/os.py", line 225, in makedirs
        mkdir(name, mode)
    PermissionError: [Errno 13] Permission denied: '/Users'
    ```
    However, it works when downloading other contracts with different addresses.
    opened by learnerLj 1
  • bug: wrong source code layout by utilizing download_src

    bug: wrong source code layout by utilizing download_src

    The file layout shows below after successfully getting the source code from https://bscscan.com/address/0x9059f2f644402db18155b7917762823a58962397#code image

    But the contract 0x9059F2F644402DB18155B7917762823A58962397/contracts/math/Math.sol is not in the proper directory because of the statement import "@openzeppelin/contracts/math/Math.sol"; at line#7 at contracts/v2/MerlinStrategyAlpacaBNB.sol image

    opened by learnerLj 1
Owner
Moon
Moon
Command line, configuration and persistence utilities

Zensols Utilities Command line, configuration and persistence utilities generally used for any more than basic application. This general purpose libra

Paul Landes 2 Nov 17, 2022
eBay's TSV Utilities: Command line tools for large, tabular data files. Filtering, statistics, sampling, joins and more.

Command line utilities for tabular data files This is a set of command line utilities for manipulating large tabular data files. Files of numeric and

eBay 1.4k Jan 9, 2023
Collection of useful command line utilities and snippets to help you organise your workspace and improve workflow.

Collection of useful command line utilities and snippets to help you organise your workspace and improve workflow.

Dominik Tarnowski 3 Dec 26, 2021
AML Command Transfer. A lightweight tool to transfer any command line to Azure Machine Learning Services

AML Command Transfer (ACT) ACT is a lightweight tool to transfer any command from the local machine to AML or ITP, both of which are Azure Machine Lea

Microsoft 11 Aug 10, 2022
A cd command that learns - easily navigate directories from the command line

NAME autojump - a faster way to navigate your filesystem DESCRIPTION autojump is a faster way to navigate your filesystem. It works by maintaining a d

William Ting 14.5k Jan 3, 2023
Ros command - Unifying the ROS command line tools

Unifying the ROS command line tools One impairment to ROS 2 adoption is that all

null 37 Dec 15, 2022
Python command line tool and python engine to label table fields and fields in data files.

Python command line tool and python engine to label table fields and fields in data files. It could help to find meaningful data in your tables and data files or to find Personal identifable information (PII).

APICrafter 22 Dec 5, 2022
PwnWiki command line searching tool & bindings written in Python

pwsearch PwnWiki 数据库搜索命令行工具。 安装 您可以直接用 pip 命令从 PyPI 安装 pwsearch: pip3 install -U pwsearch 您也可以 clone 该仓库并直接从源码启动

PwnWiki 20 Jun 21, 2021
PyArmor is a command line tool used to obfuscate python scripts

PyArmor is a command line tool used to obfuscate python scripts, bind obfuscated scripts to fixed machine or expire obfuscated scripts.

Dashingsoft 2k Jan 7, 2023