1.0.4 • Published 2 years ago

eth-tweet v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Ethereum Twitter Analysis

Overview

This doc is a step-by-step guide for Twitter analysis based on ENS names.

sample output output

Getting Started

install this package in your javascript/typescript project

npm i --save eth-tweet

Steps

There are 2 foundational steps for working with the ENS api and Twitter api at the same time.

The examples section includes the other things that you can do with the data.

Step-1: Find the data

You should have a csv dataset that has a column on it that has the information of the ens names.

You can leave out all the other columns in your dataframe. Just make sure that the ENS column exists. That’s all!

If you’ve been working with pandas to make your dataset, you can use pd.to_csv(path=path) and give it a name.

example

pd.to_csv("whales.csv")

Step-2: Talk to ENS

In the ENS website, everyone can link their social accounts to their .eth names. ENS has provided a library for us to find this data programmatically. Unfortunately, the only way to access this functionality is through Javascript. Though you don’t have to know anything about Javascript to do this, the function is already written for you! You only need to run it. So please make sure you have Node.js installed on your machine. I highly recommend the LTS version.

  • If you don’t know js, toggle this Once you’ve got your node.js setup, make sure you run a simple hello world program in javacript just to see if it works the way you expect.
    console.log("hello world")
    and then run in your terminal
    node hello.js // Or whatever your filename was

Now cd to the directory and run npm install to get all the packages you need

So I told you I’ve done the hard part right? You only need to follow the code gist and checklist here:

  • Make sure you have an ethereum node api key, You can use Alchemy or Infura. It has to be mainnet

Importing ethers has already been done, just initialize this provider.

const provider = new ethers.providers.JsonRpcProvider(
   YOUR API KEY
// ie  "https://mainnet.infura.io/v3/12345"
)
  • Run this function with the following arguments

The function is the only thing you need to call to get the data you need.

import { getTwitterHandles } from "eth-tweet"

Here’s the signature of the function:

async function getTwitterHandles(
    provider: Provider,
    csv: string,
    outputPath: string,
    ensColName: string
)
  • provider: The ethers.js provider we made in our first checkmark!
  • csv: The csv relative path to your csv file you exported in the first step
  • outputPath: The path of the output, I haven’t tried with a different directory than the cwditself. If you’re on linux, it might not be able to save the output to a different directory because of permissions. Note: all the files are prefixed by a .txt in the end, this is a convention in the function’s code
  • ensColName: Remember the dataset you exported in the first step? This functions needs only one column and that is the ensColName. You provide the name of the column that contains the ENS values. The function doesn’t care about the rest honestly.

run the file you have made using node after providing the arguments. Below is a sample argument.

getTwitterHandles(provider, "./whales.csv", "./whales", "ENS")

That’s it! You now have it setup blazingly fast. Just a quick note, the function will log everytime it tries to fetch an ENS name’s twitter. For every ENS name, there are two logs:

One that says fetching example.eth

other says fetched example.eth

my terminal has been frozen...

please make sure to check the logs every few minutes, if the logs have frozen and nothing is being updated, it’s a sign that it’s reached the end. You can check the txt file of the output (spoiler: you’ll see a bunch of NaN values) and safely CTRL+Cto stop node from executing the program if it doesn’t stop on finish time.

The finish line 🏁

That’s it. Now you have the output file. One quick note before you go and explore. The program attempts to find the twitter usr name out the ens user. If it can’t find it, it’ll write a 'NaN'string value. This is different from np.nan or undefiendin js land.

I recommend you to have a filter that checks strict equality (ie == if you’re in python, === if you’re in js) to check for equality with ‘NaN’ strings.

However, if it can find it, the output will be:

ensName++TwitterUsername

and example of this is:

lossy.eth++lossyeth
1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago