I am a crypto investor. I am staking a coin but the smart contract requires the user to claim and restake the rewards by transacting a smart contract function every 24 hours. Currently I am doing it manually, which is wasting time. To my understanding, I can just write a program to call this smart contract function to claim and restake automatically. I am already doing similar things to fetch on-chain values (read contract) from Ethereum using Python, web3py, and that program was deployed to the cloud as a Docker container app. However if I want to do something that changes the state (write contract), I will need to provide the private key in order to sign the transaction. This raises a security concern because I am not sure about the best practice on how to store the private key securely.

I have the following proposals:

  1. I can use a cloud instance, e.g. AWS EC2 and run my Python code there. I can use a .env file to store the private key and inject the private key only during runtime as an environment variable. Or I should totally avoid saving the private key to disk, and instead, just export the key as an environment variable via SSH shell. However, I doubt that even if the code is dockerized, maybe the private key is still accessible to AWS’s staff, and therefore still not secure?
  2. Another approach is, I can use a Raspberry Pi which will be online 24/7 running scheduled cron jobs using my home network. But the only worry is the network downtime. Also, If the Raspberry Pi is connected to the Internet, I still hesitate to just save the private key as a plain text .env file even on an encrypted SD card. How should I encrypt that plain text secret file and make it accessible only to just one container?

Anyway, can you think of a better solution to this task? Or maybe I’d better ask, in general, what is the best practice to store the secrets if your container app needs to constantly sign digital signatures but at the same time it needs to be run on the cloud?

Pls help. Thx.

  • How about pre-signing a bunch of transactions and only sending them out to the network periodically? May 20, 2022 at 6:34

1 Answer 1


One option I can think of in regards to AWS is to use the secret store to keep the private key. You have to modify your code to load the key from the secret store and could use it than to sign the transaction.

AWS also has a KMS, which can sign transactions for you. But I am not sure if you can load your private key into the KMS and then sign the data. Use Key Management Service (AWS KMS) to securely manage Ethereum accounts: Part 1

Your Answer

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

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