DEV Community

Ycrypto-3
Ycrypto-3

Posted on

How to get Wallet Addresses from Comment section of a Tweet

If you want to perform an airdrop or a marketing campaign on twitter, but wonder how you're going to get all the wallet addresses from comments, Here's a quick and easy way to do that!

Sign up to get twitter development access(https://developer.twitter.com/en/portal/dashboard), once you're done

Create a project
Image description

and get your BEARER token

Image description

Now to the Code!

Requirements
Node Js 16 and Up
Axios

import fs from "fs"; 
import axios from "axios";
var resultsNext_token = "";
var count = 0;
var arrayWallets = [] //Array of wallets
var regexPattern = /[^A-Za-z0-9]/g //Removes Pesky emojis and non alphanumerical text; 

async function runthis(id){
while (count < 13) { //Count is num *100(100 comments per request) so this goes through 1,300 comments
  const response = await axios.get(
    `https://api.twitter.com/2/tweets/search/recent?query=conversation_id:${id}&max_results=100&tweet.fields=in_reply_to_user_id,author_id,created_at,conversation_id&${
      resultsNext_token ? `next_token=${resultsNext_token}` : ""
    }`,
    {
      headers: {
        Authorization: `Bearer ${BEARER}`,
      },
    }
  );
  const resultsArray = response.data.data;
  resultsNext_token = response.data.meta.next_token;
  if (resultsArray != undefined) {
    resultsArray.map(data=>{
      const datatext = data.text.replaceAll("\n"," ").split(" ")
      datatext.map((data)=>{
        if(data.length>30){ // Checks for long strings(possibily wallets)
          arrayWallets .push(data.replace(regexPattern, ""))
        }
    })
    })
    // arrayWallets  = [...arrayWallets ,...resultsArray]

    count = count + 1;
    if(count ==13){ // after 1300 comments searched
      let data = JSON.stringify(arrayWallets );

fs.writeFileSync("walletArrayOut.json", data); // stores wallets in a json file as an array
    }
  } else {
    return false;
  }
}
Enter fullscreen mode Exit fullscreen mode

And There you have it, Hope it helps!

Top comments (1)

Collapse
 
houta97 profile image
houta97

this is very interesting ser but i'm not a dev and many ppl dont understand how to use this script please elaborate