Skip to content

Wallet Setup

Create New Wallet

from eth_account import Account

wallet = Account.create()
print(f"Address: {wallet.address}")
print(f"Private Key: {wallet.key.hex()}")
# IMPORTANT: Save your private key securely!

Import Existing Wallet

From Private Key

wallet = Account.from_key("0x_your_private_key_here")

From Mnemonic (Seed Phrase)

wallet = Account.from_mnemonic(
    "word1 word2 word3 word4 word5 word6 word7 word8 word9 word10 word11 word12"
)

From Keystore File

with open("keystore.json") as f:
    keystore = json.load(f)
wallet = Account.from_key(Account.decrypt(keystore, "your_password"))

Fund Your Wallet

Step 1: Get Base ETH (for gas)

Gas on Base is very cheap (~$0.001 per transaction).

Step 2: Get USDC on Base

UsageUSDCBase ETH
Testing$1$0.10
Light usage$10$0.50
Active trading bot$100$2.00
Heavy usage$500+$5.00

Check Balance

Via Basescan

Visit: https://basescan.org/token/0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913?a=YOUR_ADDRESS

Via Python

from web3 import Web3

w3 = Web3(Web3.HTTPProvider("https://mainnet.base.org"))

# ETHbalance
eth_balance = w3.eth.get_balance(wallet.address)
print(f"ETH: {w3.from_wei(eth_balance, 'ether')}")

# USDC balance (6 decimals)
usdc_address = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
usdc_abi = [{"constant":True,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"type":"function"}]
usdc = w3.eth.contract(address=usdc_address, abi=usdc_abi)
balance = usdc.functions.balanceOf(wallet.address).call()
print(f"USDC: {balance / 1e6}")

Never hardcode private keys in source code. Use environment variables:

export FOURSEC_WALLET_KEY="0x_your_private_key"

Then in Python:

import os
wallet = Account.from_key(os.environ["FOURSEC_WALLET_KEY"])

WARNING

Never commit private keys to Git. Add .env to .gitignore.

Hardware Wallets

For production use, consider hardware wallets:

  • Ledger: Use ledgereth library
  • Trezor: Use trezor-connect library

TIP

For development, a software wallet is fine. For production bots managing significant funds, use a hardware wallet or multi-sig.

Released under the MIT License.