0
from solcx import compile_standard
import json
from web3 import Web3
import os
from dotenv import load_dotenv



my_address = "0xDFb3e342C0A8F724bfA72e5F2773a12748977f46"
private_key = os.getenv("PRIVATE_KEY")

I am learning solidity and when I use python-dotenv to import my PRIVATE_KEY from a .env file,

export PRIVATE_KEY = 0xd6a5ea3d2c97b1dd03fd1b9c447e36791522135136665f23b0c08c6395f66d7a

it imports it as none and throws an error. this error I have given the full script that I wrote above. I hope someone can help me solve this problem

Yilmaz
  • 35,338
  • 10
  • 157
  • 202
LockE404
  • 29
  • 3
  • You first need to use the load_dotenv() function in order to load your environment variables. You can refer to this question: https://stackoverflow.com/questions/65693810/os-getenvtoken-returns-none-with-token-defined-in-env/65694089#65694089 – Marc Dillar Jan 09 '22 at 06:31

1 Answers1

0
  • Make sure .env file is in the same directory.

  • Calling load_dotenv will look for .env file and sets the environment variables

    load_dotenv()
    

if .env file is not in the same directory you have to pass the path of .env file to load_dotenv

 load_dotenv(path_of_env)
Yilmaz
  • 35,338
  • 10
  • 157
  • 202