0

i am trying to interpret a code for buying tokens through Pancakeswap using Python. I got stuck at the Private Key where the variable is "config.private" in the code. But I have seen other similar codes where they put private_key = "xxxxxxxxxxxxxxxxxxxxx".

The explanation I saw in the video where you put the variable like "config.private" is to prevent them from seeing your private key and put it as an imported script from another file.

I don't know the ".private" module from the config library. I would like to know the process you did in the other file and how you linked it to the line of code in the working file.

signed_txn = web3.eth.account.sign_transaction(pancakeswap2_txn, private_key=config.private)

1 Answer 1

1

Create a config.py in the same directory with the file you want to import config, put to this file

private="xxxxx"

In the file you want to import

import config
...
print(config.private) // xxxxx

And add config.py to .gitignore file

5
  • It worked but i have a few questions. First: What is ".gitignore file"? / Second: when you call "print(config.private)", "config." is a reference to name of config.py or the library imported?".private" is a reference of the variable defined in the second py doc? because i cannot understand the use of "import config" right there. Jan 5, 2022 at 6:23
  • Next time I suggest you referent the link to the example where you have seen the code. I googled the piece of code github.com/CodeWithJoe2020/pancakeswapBot/blob/main/…. So I try to explain based on this code. config is a reference to the file config.py. .private is reference to private variable. It is the way python imports external source code. .gitignore is the ways you keep the file secret. Git will ignore all the file with the name match the regex define in this file. The
    – Nhan_nht
    Jan 5, 2022 at 7:24
  • Because the private usually secret data, it should keep hidden only in local machine, so we must add it from an external file, and keep this external file private (private mean not public it to git hosting service). This is why we put the file name to .gitignore
    – Nhan_nht
    Jan 5, 2022 at 7:31
  • I think I should add some useful resources here because all the things I said is very basic terms in programming. About import technique in Python:realpython.com/python-import/#example-structure-your-imports. About gitignore: stackoverflow.com/questions/27850222/what-is-gitignore-exactly/…
    – Nhan_nht
    Jan 5, 2022 at 7:33
  • Thank you so much, i've finally understand that. Yes, based on that piece of code i tried to interpret Python language and that part was the last line of code to understand if you can see my last questions hahaha I forget to say that i am newbie but finally i could read my first complete coding. Thanks to give me the gift of knowledge :') Jan 5, 2022 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.