-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeployContract.py
More file actions
55 lines (43 loc) · 1.37 KB
/
Copy pathdeployContract.py
File metadata and controls
55 lines (43 loc) · 1.37 KB
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
import json
from web3 import Web3
from solc import compile_standard
#Lectura del contrato inteligente escrito en Solidity
f = open ('PeopleContract.sol','r')
contractFile = f.read()
f.close()
#Compilación del contrato
compiled_sol = compile_standard({
"language": "Solidity",
"sources":{
"PeopleContract.sol":{
"content": contractFile
}
},
"settings":{
"outputSelection":{
"*": {
"*": ["metadata", "evm.bytecode", "evm.bytecode.sourceMap"]
}
}
}
})
#Obtención del bytecode del contrato
bytecode = compiled_sol['contracts']['PeopleContract.sol']['PeopleContract']['evm']['bytecode']['object']
f = open ('PeopleContract.bytecode','w')
f.write(bytecode)
f.close()
#Obtención del abi del contrato
abi = json.loads(compiled_sol['contracts']['PeopleContract.sol']['PeopleContract']['metadata'])['output']['abi']
textAbi = json.dumps(abi)
f = open ('PeopleContract.abi','w')
f.write(textAbi)
f.close()
#Conexión a la red
w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:7545"))
w3.eth.defaultAccount = w3.eth.accounts[0]
#Intancia del contrato
PeopleContract = w3.eth.contract(abi=abi, bytecode=bytecode)
#Despliegue del contrato
tx_hash = PeopleContract.constructor().transact()
tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
print("Contract Address: ", tx_receipt.contractAddress)