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 details)

Uploaded Source

Built Distribution

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

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: web3_upgradeable_contract-0.1.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.19.0-38-generic

File hashes

Hashes for web3_upgradeable_contract-0.1.0.tar.gz
Algorithm Hash digest
SHA256 98f8f16ed01288e4ac7df9e2f2a1153f21986b98a9b61f4781a45a5423bb6953
MD5 ff89071dea82465554646735be8d974f
BLAKE2b-256 ff86ea2ca72bf18b2514d0dac12dd4b77db92674e1f75c2facc08834bf1de50f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for web3_upgradeable_contract-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 010200600c44a68b38488d7f77a0d872fe6f1e2887141eb289ab3a9b5dd2e8ea
MD5 7874a10d53c516e796d79772143b0de5
BLAKE2b-256 55d404f406d6225aaf5a70acfc2cd6ebd31e39308dac813e604d8014f003b3af

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