-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy_tic2.py
47 lines (35 loc) · 1.71 KB
/
deploy_tic2.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
#!/usr/bin/env python3
# exec(open("../Setups/cardano.py").read())
# desde que cuenta deployo
_accN = 0
# este lo uso para mandar desde el creador
txargs = {
"from": acc[_accN],
"gasPrice": web3.toWei('5', 'gwei'),
# "gasPrice": 1,
"gas": 2000000,
"nonce": web3.eth.getTransactionCount(acc[_accN]),
"value": 0
}
with open("../Contratos/Compilado/TicTacToe2.abi") as contract_abi_file:
contract_abi = json.load(contract_abi_file)
with open("../Contratos/Compilado/TicTacToe2.bin") as contract_bin_file:
contract_bytecode = '0x' + contract_bin_file.read()
# este solo construye la instancia, pero no deploya
contract_instance = web3.eth.contract(abi=contract_abi, bytecode=contract_bytecode)
# este es el que deploya desde acc0
unsigned_txn = contract_instance.constructor().buildTransaction(transaction=txargs)
signed_txn = web3.eth.account.signTransaction(unsigned_txn, private_key=private_key[_accN])
tx_hash = web3.eth.sendRawTransaction(signed_txn.rawTransaction)
# esta predice donde va a estar el contrato.
contract_address = generate_contract_address(acc[_accN], web3.eth.getTransaction(tx_hash).nonce)
#contract_address = "0x02F62A1e10C3ED6eA170856f505703f834D49779"
# Una vez que calcule la direccion del contrato, se la asigno a la instancia
contract_instance = web3.eth.contract(address = contract_address, abi = contract_abi, bytecode = contract_bytecode)
print("Deployment hash:", tx_hash.hex())
print("Deployment address:", contract_instance.address)
print("Please wait for the contract to be mined...")
# Esto hace que espere a ser minado y le asigna a ticket los valores del recibo
ticket = web3.eth.waitForTransactionReceipt(tx_hash.hex());
# de ticket tambien puedo sacar la address como
# ticket.contractAddress