Skip to main content

Minimal Python library to compile Solidity contracts and deploy them to EVM-compatible chains

Project description

evmdeploy

A lightweight, configuration-driven Python library for compiling and deploying Solidity smart contracts to EVM-compatible blockchains.

Table of Contents


Features

  • Configuration-Driven Compilation: Define compiler versions, path remappings, and optimizer settings once using the SolidityCompiler object.
  • Unified Contract API: The Contract class encapsulates ABI, bytecode, and deployment behavior in a single interface.
  • Automated Deployment Flow: Built-in support for nonce management, EIP-1559 gas estimation, and transaction confirmations.
  • Artifact Persistence: Save and load compiled contracts via JSON to eliminate redundant compilation steps.
  • OpenZeppelin Support: Easily handle library imports with customizable path remappings.
  • Multi-Chain Support: Pre-configured network settings for Ethereum Mainnet, Sepolia, Polygon, and Amoy.

Installation

You can install evmdeploy directly from PyPI:

pip install evmdeploy

Manual Installation

If you are working with the source code or want to install from the repository:

  1. Clone the repository:
git clone https://github.com/rakibhossain72/evmdeploy.git
cd evmdeploy
  1. Install dependencies:
pip install -r requirements.txt
  1. Install the package in editable mode:
pip install -e .

Setup

The library integrates with python-dotenv for managing sensitive credentials. Create a .env file in your project root:

PRIVATE_KEY=0xyour_private_key_here
RPC_URL=https://sepolia.infura.io/v3/your_project_id

Quick Start

The following example demonstrates a complete workflow from compilation to deployment.

import os
from web3 import Web3
from dotenv import load_dotenv
from evmdeploy import SolidityCompiler, Contract

# Load credentials
load_dotenv()

# 1. Configure and Compile
compiler = SolidityCompiler(solc_version="0.8.23", optimizer=True, runs=500)
artifacts = compiler.compile("contracts/Vault.sol")
vault = Contract(artifacts["Vault"])

# 2. Setup Web3 connection
w3 = Web3(Web3.HTTPProvider(os.getenv("RPC_URL")))

# 3. Deploy Contract
# The deploy() method handles gas estimation, nonces, and waiting for confirmation.
result = vault.deploy(
    w3=w3,
    private_key=os.getenv("PRIVATE_KEY"),
    constructor_args=["0x70997970C51812dc3A010C7d01b50e0d17dc79C8"]
)

print(f"Contract Address: {result.contract_address}")
print(f"Transaction Hash: {result.tx_hash}")

# 4. Save Artifact for future use
vault.save(base_path="artifacts")

Core Components

SolidityCompiler

The SolidityCompiler class allows you to pre-define your build environment.

  • solc_version: The Solidity compiler version (e.g., "0.8.23").
  • remappings: Dictionary for import path mapping (e.g., {"@openzeppelin/": "contracts/lib/openzeppelin-contracts/"}).
  • optimizer: Boolean to enable Solidity optimizer (default: True).
  • runs: Optimizer runs setting (default: 200).

Contract

The primary interface for interacting with your contract's artifacts and lifecycle.

  • deploy(...): Performs the full deployment transaction and returns a DeploymentResult.
  • save(base_path): Persists the ABI and bytecode to a JSON file.
  • from_storage(name, base_path): Class method to load a contract from saved artifacts without recompiling.
  • encode_constructor_args(*args, **kwargs): Returns the ABI-encoded data for contract initialization.

ArtifactStorage

Handles reading and writing contract data to the local filesystem.

  • save_artifacts(artifacts_dict): Saves multiple artifacts at once.
  • load_artifact(name): Retrieves a specific artifact by its contract name.

Network Support

Use get_network(name) to access pre-defined configurations for common EVM chains:

  • mainnet
  • sepolia
  • polygon
  • amoy (Polygon Testnet)
from evmdeploy import get_network
network = get_network("sepolia")
print(f"Network: {network.name}, ChainID: {network.chain_id}")

Examples

  • Standard Deployment: See examples/improved_deploy.py for a standard contract deployment flow.
  • OpenZeppelin ERC20: See examples/oz_erc20_deploy.py for an example using external library remappings and constructor arguments.

Troubleshooting

Private Key Not Found

If you receive a message saying Please set the PRIVATE_KEY environment variable, ensure:

  1. A .env file exists in the directory where you are executing the script.
  2. load_dotenv() is called at the start of your script.
  3. Your .env file contains PRIVATE_KEY=0x... without spaces around the =.

Compilation Failures

  • Verify that the solc_version in your SolidityCompiler config is installed and matches your contract's pragma.
  • Check that remappings paths are correct relative to your execution directory.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

evmdeploy-0.1.0.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

evmdeploy-0.1.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file evmdeploy-0.1.0.tar.gz.

File metadata

  • Download URL: evmdeploy-0.1.0.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for evmdeploy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 830aa34de196f8e22f6101e06a35792e50325654125389d978571283987a07da
MD5 157891b045d1a90d5ef3244a54355bf8
BLAKE2b-256 710c87fc605db7435f728d9ed9f13abf4222e7b141565ddb7940e4fbfd710985

See more details on using hashes here.

File details

Details for the file evmdeploy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: evmdeploy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for evmdeploy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2245dfbc520ff06e621e273fe4db9e683bb9be97d2b5bf08002ef137c4e6e067
MD5 d4ed90385fbf7aa1917b98b74c91d861
BLAKE2b-256 8dc2c49da8403aefa0819ac083a25f0670249217e8870c94dd0c696f02367910

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page