Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

231
Visualizações
Hi, I have a Solidity beginner question: I am trying to deploy a contract with signed transaction
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) 

I get a traceback problem starting with the signed transaction: signed_txn = w3.eth.account.sign_transaction(transaction, private_key=private_key)

strong text

  • **ganache ACCOUNT ADDRESS 0x0fcFb4dBbacfD7AcE1829b228766cd39b4791347

on my .env file , I have defined the PRIVATE KEY from ganache:

export const PRIVATE_KEY2 = "some private key from ganache"
export const SOME_OTHER_VAR = 7**

I also have a gitnore file: .env

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I guess I just re installed dotenv....some how that worked, even though I probably installed it previously....somehow...

I entered pip install python-dotenv on the terminal, and things worked from there. I am following some of Patric Alpha's soldity/python tutorial...

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda