Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!