Skip to main content

Deploy contract with transparent upgradeable proxy schema

Project description

Web3 upgradeable contract

codecov

Deploy contract with transparent upgradeable proxy schema. Inspired in deployProxy implementation from OpenZeppelin.

Python library to deploy Ethereum contracts using the transparent upgradeable proxy schema with:

  • Python ^3.10
  • Web3 ^6.0.0

Usage

from web3 import Web3, middleware
from upgradeable_contract import UpgradeableContract
import solcx

box_contract = """
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Box {
    uint256 private value;

    event ValueChanged(uint256 newValue);

    function store(uint256 newValue) public {
        value = newValue;
        emit ValueChanged(newValue);
    }

    function retrieve() public view returns (uint256) {
        return value;
    }
}
"""

solcx.install_solc("0.8.19")
artifact = solcx.compile_source(
    box_contract,
    output_values=["abi", "bin"],
    solc_version="0.8.19",
)["<stdin>:Box"]
abi, bytecode = artifact["abi"], artifact["bin"]

private_key = "0x0000000000000000000000000000000000000000000000000000000000000000"
rpc_url = "http://127.0.0.1:8545"
w3 = Web3(Web3.HTTPProvider(rpc_url))
account = w3.eth.account.from_key(private_key)
w3.eth.default_account = account.address
w3.middleware_onion.add(middleware.construct_sign_and_send_raw_middleware(account))

contract: UpgradeableContract = w3.eth.contract(
    abi=abi, bytecode=bytecode, ContractFactoryClass=UpgradeableContract
)
implementation_address, admin_address, proxy_address = contract.deploy_proxy()

print(f"Implementation contract deployed at: {implementation_address}")
print(f"ProxyAdmin contract deployed at: {admin_address}")
print(f"TransparentUpgradeableProxy contract deployed at: {proxy_address}")

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

web3_upgradeable_contract-0.1.0.tar.gz (10.2 kB view hashes)

Uploaded Source

Built Distribution

web3_upgradeable_contract-0.1.0-py3-none-any.whl (10.8 kB view hashes)

Uploaded Python 3

Supported by

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