-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.py
78 lines (64 loc) · 2.32 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
77
78
import getpass
import json
import sys
import solcx
from solcx import compile_standard
from web3 import Web3
from dapp.credentials import WEB3_PROVIDER_URL
solcx.install_solc('0.8.19')
w3 = Web3(Web3.HTTPProvider(WEB3_PROVIDER_URL))
sepolia = 11155111
# Input private key
private_key = getpass.getpass(prompt='Private key: ')
private_key = '0x'+private_key
sys.stdout.write(f'\r Reading admin details... ')
with open('admin/admin.json') as json_file:
admin_details = json.loads(json_file.read())
admin_wallet = admin_details['wallet']
sys.stdout.write(f'\r Reading contract... ')
with open('contract/eVote.sol', 'r') as contract_file:
contract = contract_file.read()
# Compile
sys.stdout.write(f'\r Compiling contract... ')
compiled_solidity = compile_standard(
{
"language": "Solidity",
"sources": {
"evote.sol": {
"content": contract
}
},
"settings": {
"outputSelection": {
"*": {"*": ["abi", "metadata", "evm.bytecode", "evm.sourceMap"]}
}
}
},
solc_version="0.8.19"
)
ABI = compiled_solidity['contracts']['evote.sol']['EVoting']['abi']
BYTECODE = compiled_solidity['contracts']['evote.sol']['EVoting']['evm']['bytecode']['object']
# Deployment
contract_instance = w3.eth.contract(abi=ABI, bytecode=BYTECODE)
nonce = w3.eth.getTransactionCount(admin_wallet)
sys.stdout.write(f'\r Building transaction... ')
tx = contract_instance.constructor().buildTransaction(
{
"gasPrice": w3.eth.gas_price,
"chainId": sepolia,
"from": admin_wallet,
"nonce": nonce
}
)
sys.stdout.write(f'\r Signing transaction... ')
signed_tx = w3.eth.account.sign_transaction(tx, private_key=private_key)
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
sys.stdout.write(f'\r Waiting for Tx receipt... ')
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
admin_details['contract_address'] = tx_receipt.contractAddress
print(f'\n contract_address: {tx_receipt.contractAddress}')
# Writing ABI and contract address
with open('contract/ABI.json', 'w') as ABI_file:
ABI_file.write(json.dumps(ABI))
with open('admin/admin.json', 'w') as json_file:
json_file.write(json.dumps(admin_details, indent=4))