-
Notifications
You must be signed in to change notification settings - Fork 1
/
web3connect.py
51 lines (41 loc) · 1.53 KB
/
web3connect.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
import os
import json
from web3 import Web3
# with open("contract_abi.json") as archivo:
# ABI = json.load(archivo)
with open("contracts/contract_abi.json") as f:
info_json = json.load(f)
ABI = info_json["output"]["abi"]
CONTRACT = os.environ["CONTRACT"]
WALLET = os.environ["WALLET"]
PRIV_KEY = os.environ["PRIV_KEY"]
polygon_rpc_url = 'https://endpoints.omniatech.io/v1/matic/mumbai/public'
w3 = Web3(Web3.HTTPProvider(polygon_rpc_url))
if w3.is_connected():
print("-" * 50)
print("Connection Successful")
print("-" * 50)
else:
print("Connection Failed")
contract_address = CONTRACT
contract_abi = ABI
contract = w3.eth.contract(address=contract_address, abi=contract_abi)
account_address = WALLET
private_key = PRIV_KEY
result = contract.functions.leerSaludo().call()
print("Resultado de la consulta:", result)
# # Interactuar con la función guardarSaludo
# greeting_message = "Saludos desde la casa con Jhonsito"
# function_data = contract.functions.guardarSaludo(greeting_message).build_transaction({
# 'from': account_address,
# 'gas': 3000000,
# 'gasPrice': w3.to_wei('10', 'gwei'),
# 'nonce': w3.eth.get_transaction_count(account_address),
# 'chainId': 80001,
# })
#
# signed_transaction = w3.eth.account.sign_transaction(function_data, private_key)
# transaction_hash = w3.eth.send_raw_transaction(signed_transaction.rawTransaction)
#
# print("Hash de la transacción enviada:", transaction_hash.hex())
# https://mumbai.polygonscan.com/tx/0x663fcce44e2507b9a0fb49b194149670b10fec18442d3a5b2234a682b2784a54