🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

ethereum-input-decorder

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Malware was recently detected in this package.

Affected versions:

1.2.21.2.4

ethereum-input-decorder

A module that prints Hello World on import

pipPyPI
Version
1.2.4
Weekly downloads
0
Maintainers
1
Weekly downloads
 

eth-defi-demo

A Python project demonstrating how to build decentralized finance (DeFi) applications using the eth_defi library. This project provides examples for connecting to EVM-compatible networks, interacting with ERC-20 tokens, reading on-chain data, executing swaps, and automating common DeFi workflows.

Features

  • Connect to Ethereum-compatible RPC providers
  • Load wallet from a private key
  • Read ERC-20 token information
  • Query balances
  • Build and sign transactions
  • Execute token transfers
  • Perform Uniswap swaps
  • Batch RPC requests using Multicall
  • Estimate gas fees
  • Listen for blockchain events
  • Retry failed RPC requests
  • Support multiple EVM chains

Requirements

  • Python 3.10+
  • pip
  • Access to an Ethereum RPC endpoint

Examples:

  • Infura
  • Alchemy
  • QuickNode
  • Ankr
  • Local Geth
  • Local Anvil

Installation

git clone https://github.com/example/eth-defi-demo.git

cd eth-defi-demo

python -m venv .venv

source .venv/bin/activate      # Linux/macOS

# or

.venv\Scripts\activate         # Windows

pip install -r requirements.txt

requirements.txt

web3
web3-ethereum-defi
python-dotenv
requests

Project Structure

eth-defi-demo/
│
├── examples/
│   ├── connect.py
│   ├── wallet.py
│   ├── erc20.py
│   ├── transfer.py
│   ├── swap.py
│   ├── multicall.py
│   └── events.py
│
├── utils/
│   ├── config.py
│   ├── rpc.py
│   └── wallet.py
│
├── .env.example
├── requirements.txt
├── README.md
└── main.py

Configuration

Create a .env file.

RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY

PRIVATE_KEY=YOUR_PRIVATE_KEY

CHAIN_ID=1

Never commit your private key to Git.

Example

from web3 import Web3

rpc = "https://rpc.ankr.com/eth"

w3 = Web3(Web3.HTTPProvider(rpc))

print("Connected:", w3.is_connected())

print("Latest block:", w3.eth.block_number)

Reading ERC-20 Token Information

token_name = token.functions.name().call()

symbol = token.functions.symbol().call()

decimals = token.functions.decimals().call()

total_supply = token.functions.totalSupply().call()

Reading Wallet Balance

balance = w3.eth.get_balance(wallet)

print(w3.from_wei(balance, "ether"))

Token Transfer

tx = token.functions.transfer(
    recipient,
    amount
).build_transaction(...)

Swap Example

router.swap_exact_tokens_for_tokens(...)

Typical workflow:

  • Approve token
  • Build swap transaction
  • Estimate gas
  • Sign transaction
  • Broadcast transaction
  • Wait for receipt

Multicall

Instead of sending dozens of RPC requests:

balanceOf()
symbol()
decimals()
allowance()

Combine them into a single Multicall request for improved performance.

Event Listening

Example events:

  • Transfer
  • Approval
  • Swap
  • Mint
  • Burn

Useful for:

  • Wallet monitoring
  • Trading bots
  • Analytics
  • Portfolio tracking

Supported Networks

  • Ethereum
  • Arbitrum
  • Optimism
  • Base
  • Polygon
  • BNB Chain
  • Avalanche C-Chain
  • Fantom
  • Gnosis
  • Scroll
  • zkSync Era
  • Linea

Security Recommendations

  • Never hardcode private keys.
  • Store secrets in environment variables.
  • Validate contract addresses.
  • Verify token decimals before transfers.
  • Simulate transactions before broadcasting.
  • Use HTTPS RPC providers.
  • Limit wallet permissions.
  • Protect API keys.

Common Use Cases

  • Trading bots
  • Arbitrage bots
  • Portfolio trackers
  • Yield farming automation
  • Liquidity management
  • Token analytics
  • Wallet monitoring
  • Blockchain indexing
  • Treasury management
  • DeFi dashboards

Troubleshooting

Connection failed

  • Verify RPC endpoint.
  • Check API key.
  • Confirm internet connectivity.

Insufficient funds

Ensure the wallet has enough native tokens to pay gas fees.

Transaction reverted

Common causes include:

  • Insufficient allowance
  • Slippage exceeded
  • Incorrect router address
  • Expired deadline

Contributing

Contributions are welcome.

  • Fork the repository.
  • Create a feature branch.
  • Commit your changes.
  • Submit a pull request.

License

MIT License

Disclaimer

This project is provided for educational purposes only. Always test on a testnet before interacting with mainnet assets. You are responsible for securing your private keys and verifying all transactions before signing.

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts