# generate\_wallet

## Function

```python
def generate_wallet(amount):
    addresses = []
    for i in list(range(0, amount)):
        account = Web3().eth.account.create()
        keystore = Web3().eth.account.encrypt(account.key.hex(), os.getenv('SECRET'))
        folder = "./data/wallets/{}".format(account.address)
        os.makedirs("data/wallets", exist_ok=True)
        os.makedirs(folder, exist_ok=True)
        open("{}/keystore".format(folder), 'w').write(json.dumps(keystore, indent=4))
        addresses.append(account)
    return addresses
```

## Description

* Prepare an empty list of accounts
* Loop based on desired amount of wallets to generate
* Create a new account/wallet
* Encrypt the keystore for based on the SECRET found in “.env”
* Set the wallet folder for the public key
* Create the parent wallet folder if it doesn’t exist
* Create the public key folder if it doesn’t exist
* Save the account’s keystore
* Add the account to the list
* Return the list of accounts


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://affection.gitbook.io/docs/bots-and-scripts/core-functions/generate_wallet.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
