Deploy contract with transparent upgradeable proxy schema
Project description
Web3 upgradeable contract
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for web3_upgradeable_contract-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98f8f16ed01288e4ac7df9e2f2a1153f21986b98a9b61f4781a45a5423bb6953 |
|
MD5 | ff89071dea82465554646735be8d974f |
|
BLAKE2b-256 | ff86ea2ca72bf18b2514d0dac12dd4b77db92674e1f75c2facc08834bf1de50f |
Close
Hashes for web3_upgradeable_contract-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 010200600c44a68b38488d7f77a0d872fe6f1e2887141eb289ab3a9b5dd2e8ea |
|
MD5 | 7874a10d53c516e796d79772143b0de5 |
|
BLAKE2b-256 | 55d404f406d6225aaf5a70acfc2cd6ebd31e39308dac813e604d8014f003b3af |