string indices must be integers but I swear I am typecasting it right. Here is the code.
try:
with open('config.yaml', "r") as file:
data = yaml.safe_load(file) or {} # If file is empty, return an empty dictionary
except FileNotFoundError:
data = {}
print(wallet) # Debugging linemy_address = wallet['address']
data["wallet"] = myAddr
data["wallet"]["tokens"] += tokens
with open("config.yaml", 'w') as file:
yaml.dump(data, file, default_flow_style=False)
print(f"Tokens saved to {config.yaml}")
def myWalletTokens(my_address):
url = f"https://api.etherscan.io/api?module=account&action=tokentx&address={my_address}&apikey={config.get_apis().get('etherscan')}"
response = requests.get(url).json()
tokens = set()
if response["status"] == "1": # Success
for tx in response["result"]:
tokens.add(tx["contractAddress"]) # Collect unique token contract addresses
print("Tokens found in wallet:", tokens)
tokens_list = list(tokens)
updateWalletConfig(my_address, tokens_list)```
here is the yaml file structure
```wallet:
address: "aaa" # Replace with your wallet address
private_key: "aaa" # Replace with your wallet private key
tokens:
- "0xTokenAddress1"
- "0xTokenAddress2"
Please help!