from solcx import compile_standard, install_solc import json from web3 import Web3 import os from dotenv import load_dotenv load_dotenv() with open("./SimpleStorage.sol", "r") as file: simple_storage_file = file.read() # print(simple_storage_file) # compile our solidity install_solc("0.6.0") compiled_sol = compile_standard( { "language": "Solidity", "sources": {"SimpleStorage.sol": {"content": simple_storage_file}}, "settings": { "outputSelection": { "*": {"*": ["abi", "metadata", "evm.bytecode", "evm.sourceMap"]} } }, }, solc_version="0.6.0", ) # print(compiled_sol) with open("compiled_code.json", "w") as file: json.dump(compiled_sol, file) bytecode = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["evm"][ "bytecode" ]["object"] # get abi abi = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["abi"] # for connecting to ganache w3 = Web3(Web3.HTTPProvider("HTTP://127.0.0.1:7545")) chain_id = 1337 my_address = "0x0fcFb4dBbacfD7AcE1829b228766cd39b4791347" private_key = os.getenv( "PRIVATE_KEY2" ) # this is after you define private key in terminal s # print(private_key) # private key gets # create contract in python SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode) # print(SimpleStorage) nonce = w3.eth.getTransactionCount(my_address) # print(nonce) # 1 build a transaction # 2 sig a transactiob # 3 send a transactjkns transaction = SimpleStorage.constructor().buildTransaction( { "gasPrice": w3.eth.gas_price, "chainid": chain_id, "from": my_address, "nonce": nonce, } ) # print(transaction) signed_txn = w3.eth.account.sign_transaction(transaction, private_key=private_key) print(signed_txn)Obtengo un problema de rastreo que comienza con la transacción firmada: firm_txn = w3.eth.account.sign_transaction(transaction, private_key=private_key)
texto fuerte
en mi archivo .env, he definido la CLAVE PRIVADA de ganache:
export const PRIVATE_KEY2 = "some private key from ganache" export const SOME_OTHER_VAR = 7**También tengo un archivo gitnore: .env
Supongo que acabo de volver a instalar dotenv... de alguna manera funcionó, aunque probablemente lo instalé anteriormente... de alguna manera...
Ingresé pip install python-dotenv en la terminal y todo funcionó desde allí. Estoy siguiendo algunos de los tutoriales de soldity/python de Patric Alpha...