How to Detect Invalid Ethereum wallets/addresses, then send them to Google Sheets (using Python)

Nicholas K Koech
2 min readJul 3, 2022

--

Motivation:

Data cleansing is an integral activity during data migration. With the emergence of Web 3.0, wallet addresses are valuable for users who interact with any blockchain platform. The same applies to startups that deal with large datasets of wallet addresses. They have to ensure that users log invalid addresses, or else things are gonna get messy!

In this article, I will create a python program you can use to detect invalid Ethereum addresses (both hexadecimal and ENS addresses) and send the data to Google Sheets(Gsheets) so that some action can be taken by other teams who will have access to the Gsheets.

To achieve this goal, we will utilize the Web3.py API and Google Sheets API.

A peek at why this is even relevant:

  1. Imagine you are performing database migration and some Users in the current database have invalid addresses. Will you comfortably migrate invalid addresses into the next database? Of course not, right? We all want some clean data!!
  2. For instance, you want to send, let’s say ethers, to multiple addresses. You will want to ensure all those addresses are valid right?
validateETHAddress.py
Here we use infura_url(as http provider) and web3. We created the first function to convert ENS "somename.ETH or somename.eth" to hexadecimal address (0x......). The last function validates any ethereum address. If address exists, the address itself will be returned, otherwise a statement like "INVALID_ADDRESS" will be logged.
Gsheets.py
In this file, the program iterates through the dummy API data, validates ethereum addresses and invalid addresses with the names of the owners will be sent to Google Sheets. The last function serves to upload data to Google sheets. The benefits of having data in google sheets is that you can share real-time data with people in non-technical roles.

Github Source Code: Click Here!

Resources:

  1. Web3.py documentation
  2. Infura.io
  3. Gspread -python API for google sheets
  4. Google API docs

--

--