Skip to content

Commit

Permalink
refact dev-stage 1| update README.md | add test.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
whonion committed Aug 28, 2023
1 parent a6c379b commit f41d737
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 95 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ETHERSCANKEY = 'YOUR_ETHETSCAN_API_KEY'
RPCURL = 'https://mainnet.infura.io/v3/INFURA_API_KEY'
EXP_URL = 'https://etherscan.io'
Binary file added .github/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Test

on: [push] # You can customize the trigger event based on your needs

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 20 # You can specify your desired Node.js version

- name: Install Dependencies
run: npm install

- name: Run JavaScript Script
run: node main.js
130 changes: 130 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
# evm-contract-sniffer
Logs the Name,Symbol etc. of every new contract deployed on the blockchain.
[![Status](https://img.shields.io/badge/status-active-success.svg)](https://github.com/whonion/js-sniffer-deployed-contracts/blob/main/) [![Test Run](https://github.com/whonion/js-sniffer-deployed-contracts/actions/workflows/test.yml/badge.svg)](https://github.com/whonion/js-sniffer-deployed-contracts/actions/workflows/test.yml) ![Node Version](https://img.shields.io/badge/Node.js-20.5.1-blue.svg) ![Ethers Version](https://img.shields.io/badge/ethers-5.70-red.svg) ![Axios Version](https://img.shields.io/badge/axios-0.27.2-orange.svg) [![HitCount](https://hits.dwyl.com/whonion/js-sniffer-deployed-contracts.svg)](https://hits.dwyl.com/whonion/js-sniffer-deployed-contracts)</br>
## JS Sniffer deployed contracts
This script outputs address,tiker etc. of every new contract deployed on the EVM-based chains.

`main.js` preview <br>![js-sniffer-deployed-contracts](https://github.com/whonion/js-sniffer-deployed-contracts/blob/main/.github/preview.png?raw=true)<br>

### Install `Node.js`
```sh
sudo apt install git
sudo apt install nodejs
sudo apt install npm
node -v
npm -v
```

### Clone repo and install dependencies
```sh
git clone https://github.com/whonion/js-sniffer-deployed-contracts.git
cd js-sniffer-deployed-contracts
npm i
node main.js
```
92 changes: 0 additions & 92 deletions index.js

This file was deleted.

63 changes: 63 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const ethers = require("ethers");
const axios = require("axios");
require("dotenv").config();

const rpcUrl = process.env.RPCURL;
const etherscanApiKey = process.env.ETHERSCANKEY;
const expUrl = process.env.EXP_URL;
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);

// Define the ABI
const abiFile = require("./abi/abi.json");

async function main() {
let currentBlock = await provider.getBlockNumber();

console.log("Starting script for analyzing deployed contracts...");

while (true) {
try {
const liveBlock = await provider.getBlockNumber();
if (liveBlock > currentBlock) {
const block = await provider.getBlockWithTransactions(currentBlock);
console.log(`Analyzing block ${currentBlock}...`);
currentBlock++;

const contractCreationTxs = block.transactions.filter(tx => tx.creates !== null);

await Promise.all(contractCreationTxs.map(async tx => {
const contractAddress = tx.creates;

console.log("Deployed contaract: ",expUrl+'/address/'+contractAddress);
await analyzeContract(contractAddress, abiFile); // Pass abiFile as a parameter
}));
}
} catch (err) {
console.error(err);
}
await sleep(200); // Rate limit
}
}

async function analyzeContract(contractAddress, abi) { // Receive abiFile as a parameter
console.log("Analyzing contract:", contractAddress);
const contract = new ethers.Contract(contractAddress, abi, provider); // Use abi parameter

const [name, symbol, owner, totalSupply] = await Promise.all([
contract.name(),
contract.symbol(),
contract.owner(),
contract.totalSupply()
]);

console.log("Contract Name:", name);
console.log("Contract Symbol:", symbol);
console.log("Contract Owner:", owner);
console.log("Contract TotalSupply:", totalSupply);
}

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

main().catch(console.error);
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f41d737

Please sign in to comment.