-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.py
77 lines (63 loc) · 2.56 KB
/
deploy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# yarn global add ganache-cli
# yarn global bin, yarn config set prefix..
# deployment using web3.py and py-solc-x libraries
import json
import pprint
from dotenv import load_dotenv
import os
from solcx import compile_standard, install_solc
from web3 import Web3
load_dotenv()
with open('contracts1/MemeContract.sol', 'r') as f:
raw_contract = f.read()
install_solc(version="latest")
# Compile solidity code
compiled = compile_standard(
{
"language": "Solidity",
"sources": {"MemeContract.sol": {"content": raw_contract}},
"settings": {
"outputSelection": {
"*": {"*": ["abi", "metadata", "evm.bytecode", "evm.bytecode.sourceMap"]}
}
}
},
solc_version="0.8.16"
)
# get bytecode and abi of contract
bytecode = compiled["contracts"]["MemeContract.sol"]["MemeContract"]["evm"]["bytecode"]["object"]
abi = compiled["contracts"]["MemeContract.sol"]["MemeContract"]["abi"]
chain_id = 11155111
w3 = Web3(Web3.HTTPProvider("https://sepolia.infura.io/v3/92d2cb193fbd444e91175acf4e61d54c")) #
addr = "0xF41D401bA4E55C21b216923f0638bf40aDEC436D" # metamask 4fun sepolia eth addr
meme_contract = w3.eth.contract(abi=abi, bytecode=bytecode)
nonce = w3.eth.get_transaction_count(addr)
# 1. Build a transaction
# 2. Sign a transaction
# 3. Send a transaction and wait confirmation
transaction = meme_contract.constructor().build_transaction({"chainId": chain_id, "from": addr, "nonce": nonce, "gasPrice": w3.eth.gas_price})
signed_tx = w3.eth.account.sign_transaction(transaction, private_key=os.getenv("PKEY"))
print("Deploying contract...")
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
deployed_contract = w3.eth.contract(abi=abi, address=tx_receipt.contractAddress)
print("Deployed!")
tx2 = deployed_contract.functions.addSubject("Fifi", 150, True).build_transaction(
{
"chainId": chain_id,
"nonce": nonce + 1,
"from": addr,
"gasPrice": w3.eth.gas_price,
# "gas": 2000000,
# "gasPrice": 2000000,
}
)
signed_tx2 = w3.eth.account.sign_transaction(tx2, private_key=os.getenv("PKEY"))
print("Updating contract...")
tx_hash = w3.eth.send_raw_transaction(signed_tx2.rawTransaction)
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print("Updated!")
# Working with contract we need address + contract ABI
# meme_contract = w3.eth.contract(address=tx_receipt.contractAddress, abi=abi)
# Call - no state change Transact - state change
print(deployed_contract.functions.showAll().call())