DeveloperBreeze

Introduction

In this tutorial, we will learn how to track newly created tokens on the Ethereum blockchain. With the rapid growth of decentralized finance (DeFi) and non-fungible tokens (NFTs), keeping an eye on newly created tokens can be valuable for investors, developers, and enthusiasts. We will use Etherscan's API to monitor token creation events and Web3.js to interact with the Ethereum network.

Prerequisites

  • Node.js and npm installed on your system.
  • Basic knowledge of JavaScript and Ethereum.
  • An Etherscan API key (you can obtain one by signing up on Etherscan).

Step 1: Set Up Your Project

  1. Create a new project directory:
   mkdir ethereum-token-tracker
   cd ethereum-token-tracker
  1. Initialize a new Node.js project:
   npm init -y
  1. Install the necessary libraries:
   npm install web3 axios

Step 2: Connect to the Ethereum Network

Create a new file called index.js and add the following code to connect to the Ethereum blockchain:

const Web3 = require('web3');

// Connect to an Ethereum node using Infura
const web3 = new Web3('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');

console.log('Connected to Ethereum Mainnet');

Replace YOUR_INFURA_PROJECT_ID with your Infura project ID. You can sign up for a free Infura account and create a project to get the project ID.

Step 3: Fetch Newly Created Tokens

We will use Etherscan's API to fetch information about newly created tokens. Add the following function to your index.js file:

const axios = require('axios');

// Replace with your Etherscan API key
const ETHERSCAN_API_KEY = 'YOUR_ETHERSCAN_API_KEY';

async function getNewTokens() {
  try {
    const url = `https://api.etherscan.io/api?module=account&action=tokentx&address=0x0&startblock=0&endblock=99999999&sort=asc&apikey=${ETHERSCAN_API_KEY}`;
    const response = await axios.get(url);

    if (response.data.status === '1') {
      const transactions = response.data.result;
      const newTokens = transactions.filter(tx => tx.tokenSymbol && tx.tokenName && tx.from === '0x0000000000000000000000000000000000000000');

      console.log('Newly Created Tokens:');
      newTokens.forEach(token => {
        console.log(`- Token Name: ${token.tokenName}`);
        console.log(`  Token Symbol: ${token.tokenSymbol}`);
        console.log(`  Token Contract Address: ${token.contractAddress}`);
      });
    } else {
      console.error('Error fetching token transactions:', response.data.message);
    }
  } catch (error) {
    console.error('Error:', error);
  }
}

getNewTokens();

Explanation

  • Etherscan API: We use the tokentx action from Etherscan's API to fetch token transfer events. The API returns a list of token transactions, including newly created tokens.
  • Filter for New Tokens: We filter transactions where the from address is 0x0000000000000000000000000000000000000000, indicating a token creation event. This address is used as a placeholder for the "zero address" in token contracts.
  • Display Information: We log the name, symbol, and contract address of each newly created token.

Step 4: Monitor for New Tokens

You can run this script periodically to monitor for new token creation events. Consider setting up a cron job or a scheduled task to execute the script at regular intervals.

node index.js

Conclusion

In this tutorial, we explored how to track newly created tokens on the Ethereum blockchain using Etherscan's API and Web3.js. This approach provides a simple yet effective way to monitor token creation events, which can be useful for various applications in the blockchain space.

Continue Reading

Discover more amazing content handpicked just for you

Tutorial

Understanding `crypto.randomBytes` and `ethers.randomBytes`: A Comparison

    const { ethers } = require('ethers');
    const randomBytes = ethers.utils.randomBytes(32);
    console.log(randomBytes); // Uint8Array of random bytes
  • crypto.randomBytes is part of Node.js, so it requires no external dependencies. This makes it ideal for Node.js environments where minimal dependencies are desired.
  • ethers.randomBytes requires the installation of the ethers.js library, which is primarily designed for blockchain-related projects. This is useful if you're already working with Ethereum, but it adds an external dependency to the project.

Oct 24, 2024
Read More
Tutorial

How to Query ERC-20 Token Balances and Transactions Using Ethers.js and Etherscan API

You should see a list of token transactions for the specified address, with details including the sender, recipient, value transferred, and transaction hash.

You can customize the Etherscan API request to suit your needs. Here are a few options:

Oct 24, 2024
Read More
Tutorial

Etherscan vs Infura: Choosing the Right API for Your Blockchain Application

  • Use Etherscan if:
  • You only need to read blockchain data.
  • You want to build tools for analytics or explorers.
  • You don’t need to send transactions or interact directly with smart contracts.
  • Use Infura if:
  • You need to interact with the Ethereum blockchain in real-time.
  • You’re building dApps, wallets, or tools that require transactions.
  • You need to write data to the blockchain, such as sending Ether or deploying contracts.

In some cases, you might want to use both Etherscan and Infura. For example, you might use Etherscan to query transaction histories or token transfers, and Infura to send transactions or deploy contracts.

Oct 24, 2024
Read More
Tutorial

Sending Transactions and Interacting with Smart Contracts Using Infura and Ethers.js

In this tutorial, you learned how to use Ethers.js with Infura to send Ether, interact with smart contracts, and deploy contracts on the Ethereum blockchain. This setup allows you to interact with the blockchain in real-time without the need to run your own Ethereum node, making it easier to develop decentralized applications (dApps) and other blockchain-based services.

Using Infura for node access and Ethers.js for transaction management and contract interaction gives you a powerful combination to build on Ethereum.

Oct 24, 2024
Read More
Tutorial

Understanding and Using the Etherscan API to Query Blockchain Data

   https://api.etherscan.io/api?module=account&action=txlist&address=0xYourEthereumAddress&startblock=0&endblock=99999999&sort=asc&apikey=YOUR_API_KEY
   https://api.etherscan.io/api?module=account&action=tokentx&address=0xYourEthereumAddress&startblock=0&endblock=99999999&sort=asc&apikey=YOUR_API_KEY

Oct 24, 2024
Read More
Tutorial

Getting Wallet Balance Using Ethers.js in Node.js

Once you've successfully retrieved the balance, you can expand your script to add more features. For example:

  • Check the balance of other Ethereum addresses (not just your wallet).
  • Send ETH to other addresses.
  • Interact with smart contracts using Ethers.js.

Oct 24, 2024
Read More
Tutorial

Understanding 0x000000000000000000000000000000000000dead Address and Token Burns in Ethereum

For example, in token burn events, project developers often send tokens to this address to signal to the community that those tokens are now out of circulation. This is usually followed by a public announcement, detailing the number of tokens burned and the reasons behind the burn.

Token burns are typically done to increase scarcity, and scarcity can lead to a higher token value if demand remains the same or increases. The basic principle of supply and demand comes into play: when the supply of an asset is reduced, it becomes more valuable (assuming demand holds steady).

Oct 24, 2024
Read More
Tutorial

ETH vs WETH: Understanding the Difference and Their Roles in Ethereum

  • Decentralized Exchanges (DEXs): Many decentralized exchanges (like Uniswap) require ERC-20 tokens for trading. WETH allows ETH holders to trade ETH just like any other ERC-20 token.
  • DeFi Lending Platforms: Platforms such as Aave or Compound often require collateral in the form of ERC-20 tokens, making WETH essential for ETH holders who want to participate.
  • Token Swaps: WETH allows for seamless token swaps between ETH and other ERC-20 tokens on platforms that support such swaps.

ETH and WETH serve different but complementary roles in the Ethereum ecosystem. While ETH is the native currency used to power the network, WETH enables ETH to interact with the growing number of decentralized applications and DeFi protocols that rely on the ERC-20 standard. By understanding how to wrap and unwrap ETH, you can effectively engage in the broader Ethereum DeFi ecosystem without leaving the native ETH environment.

Oct 24, 2024
Read More
Cheatsheet
solidity

Blockchain Libraries Cheatsheet

  • Description: A JavaScript library for Bitcoin-related operations, including creating and signing transactions, and managing addresses.
  • Use Cases:
  • Create Bitcoin wallets and addresses.
  • Sign and broadcast Bitcoin transactions.
  • Build Bitcoin-based applications with custom scripts.
  • Key Features:
  • Lightweight and easy to use.
  • Supports SegWit (Segregated Witness) transactions.
  • Comprehensive documentation for various Bitcoin operations.
  • Installation:

Aug 23, 2024
Read More
Cheatsheet
solidity

Blockchain Development Tools, Libraries, and Frameworks Cheatsheet

  • Description: A development framework for Ethereum that provides a suite of tools for writing, testing, and deploying smart contracts.
  • Key Features:
  • Built-in smart contract compilation, linking, deployment, and binary management.
  • Scriptable deployment & migrations framework.
  • Network management for deploying to different networks.
  • Interactive console for direct contract interaction.
  • Testing framework using Mocha and Chai.
  • Website: Truffle
  • Description: A flexible and extensible development environment for Ethereum, designed to manage and automate tasks like contract compilation and deployment.
  • Key Features:
  • Local Ethereum network for testing (Hardhat Network).
  • Easy integration with popular tools like Ethers.js and Waffle.
  • Plugins for Solidity coverage, gas reporting, and more.
  • Error messages and stack traces specific to Solidity.
  • Highly customizable and scriptable.
  • Website: Hardhat

Aug 23, 2024
Read More
Tutorial
solidity

Writing an ERC-20 Token Contract with OpenZeppelin

  • Use libraries like Web3.js or Ethers.js to build a front-end that interacts with your token contract. Connect the front-end to MetaMask to allow users to interact with the contract.

If you’ve deployed your contract to a public testnet or the mainnet, you might want to verify the contract on Etherscan.

Aug 22, 2024
Read More
Cheatsheet
solidity

Solidity Cheatsheet

Use require, assert, and revert for error handling.

  • require: Checks conditions and reverts if false. Used for input validation.

Aug 22, 2024
Read More
Tutorial
solidity

Understanding Gas and Optimization in Smart Contracts

Optimizing gas consumption in smart contracts can lead to substantial cost savings, especially for frequently executed contracts. Here are some strategies to consider:

1. Minimize Storage Writes

Aug 22, 2024
Read More
Tutorial
solidity

Building a Decentralized Application (DApp) with Smart Contracts

Steps to Deploy:

Now that you’ve built a basic DApp, you can explore more complex and real-world use cases. DApps can be used in various domains, including:

Aug 22, 2024
Read More
Tutorial
solidity

Introduction to Smart Contracts on Ethereum

Before writing a smart contract, we need to set up a development environment. Here’s what you need:

  • Node.js: Used to install necessary packages and tools.
  • Remix IDE: An online integrated development environment for writing, testing, and deploying smart contracts.
  • MetaMask: A browser extension that acts as a wallet and allows you to interact with the Ethereum blockchain.

Aug 22, 2024
Read More
Tutorial
javascript solidity

Creating a Decentralized Application (dApp) with Solidity, Ethereum, and IPFS: From Smart Contracts to Front-End

To deploy your smart contract to the Ethereum mainnet, you’ll need to configure Truffle to connect to an Ethereum node (e.g., Infura) and provide a wallet with Ether to pay for gas.

Update truffle-config.js with the necessary configurations and deploy:

Aug 20, 2024
Read More
Tutorial
python

Advanced Pybit Tutorial: Managing Leverage, Stop-Loss Orders, Webhooks, and More

   def set_leverage(symbol, leverage):
       response = session.set_leverage(symbol=symbol, leverage=leverage)
       if response['ret_code'] == 0:
           print(f"Leverage set to {leverage}x for {symbol}")
       else:
           print(f"Error setting leverage: {response['ret_msg']}")
       return response

   set_leverage('BTCUSD', 10)  # Set 10x leverage on BTCUSD pair

This code sets the leverage to 10x for the BTC/USD trading pair. Adjust the leverage value as needed.

Aug 14, 2024
Read More
Tutorial
python

A Beginner's Guide to Pybit: Interacting with the Bybit API

In the rapidly evolving world of cryptocurrency trading, accessing and interacting with exchange APIs is essential for automated trading and data analysis. Pybit is a Python wrapper for the Bybit API, making it easier to access and interact with Bybit's functionalities using Python. In this tutorial, we'll walk you through the basics of setting up Pybit, fetching market data, and executing trades.

  • Basic knowledge of Python.
  • A Bybit account.
  • Installed Python packages: pybit, requests.

Aug 14, 2024
Read More
Tutorial
javascript nodejs

Tracking Solana Address for New Trades and Amounts

Step 1: Set Up Your Project

   mkdir solana-address-tracker
   cd solana-address-tracker

Aug 09, 2024
Read More
Tutorial
javascript nodejs

Tracking Newly Created Tokens on Solana

   npm install @solana/web3.js

Step 2: Connect to the Solana Network

Aug 09, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!