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

  • crypto.randomBytes:
  • Takes a single argument specifying the number of bytes.
  • Always requires a size input; no default value is provided.
  • ethers.randomBytes:
  • Optionally takes the number of bytes to generate.
  • If no argument is provided, it defaults to generating 32 bytes.

Both crypto.randomBytes and ethers.randomBytes generate cryptographically secure random bytes, meaning the bytes are suitable for use in cryptographic applications such as key generation, encryption, and other security-sensitive operations.

Oct 24, 2024
Read More
Tutorial

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

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

  • Start and End Block: Adjust the startblock and endblock parameters to limit the range of blocks you want to query.
  • Sort: Set the sort parameter to asc (ascending) or desc (descending) to control the order of the transactions.
  • Token Transfers for All Tokens: You can modify the API call to query all token transfers for an address, not just a specific token contract, by omitting the contractaddress parameter.

Oct 24, 2024
Read More
Tutorial

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

In this tutorial, we will compare Etherscan and Infura, two popular services for interacting with the Ethereum blockchain. Both provide APIs, but they serve different purposes and are suited for different types of applications. By understanding the strengths of each, you can choose the right one based on your specific use case, whether it involves querying blockchain data or interacting with the Ethereum network in real-time.

  • Basic understanding of Ethereum and blockchain concepts.
  • Familiarity with APIs and programming in Node.js or any other language.

Oct 24, 2024
Read More
Tutorial

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

const ethers = require('ethers');

// Replace with your Infura Project ID
const infuraProvider = new ethers.JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');

// Replace with your private key
const privateKey = 'YOUR_PRIVATE_KEY';

// Create a wallet instance and connect it to Infura
const wallet = new ethers.Wallet(privateKey, infuraProvider);

// Contract bytecode and ABI
const bytecode = '0xYourContractBytecode';
const abi = [
    // Your contract ABI here
];

async function deployContract() {
    try {
        // Create a ContractFactory to deploy the contract
        const factory = new ethers.ContractFactory(abi, bytecode, wallet);

        // Deploy the contract
        const contract = await factory.deploy();

        // Wait for the contract to be mined
        console.log('Contract deployed at address:', contract.address);
        await contract.deployTransaction.wait();
    } catch (error) {
        console.error('Error deploying contract:', error);
    }
}

// Call the function to deploy the contract
deployContract();
  • Bytecode and ABI: The contract bytecode is the compiled contract, and the ABI defines the contract’s interface. You need both to deploy the contract.
  • The contract will be deployed using your Infura provider and wallet, and once mined, it will return the deployed contract address.

Oct 24, 2024
Read More
Tutorial

Understanding and Using the Etherscan API to Query Blockchain Data

This script queries the wallet balance from the Ethereum blockchain using the Etherscan API.

Let’s extend the functionality by querying transaction details for a specific transaction using the Etherscan API.

Oct 24, 2024
Read More
Tutorial

Getting Wallet Balance Using Ethers.js in Node.js

If you plan to use Infura as your Ethereum provider, follow these steps:

Now, let's create a script to query the balance of an Ethereum wallet. This script will work with both Infura and public nodes.

Oct 24, 2024
Read More
Tutorial

Understanding 0x000000000000000000000000000000000000dead Address and Token Burns in Ethereum

Token burns serve several key purposes in the cryptocurrency world:

The "0x000000000000000000000000000000000000dead" address is used as a burn address because it is widely recognized as a destination for token destruction. Since tokens sent to this address are permanently locked and cannot be retrieved, it’s an ideal address for conducting token burns. It is a well-established convention across many blockchain projects.

Oct 24, 2024
Read More
Tutorial

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

  • Users deposit ETH into a smart contract.
  • The smart contract issues an equivalent amount of WETH.
  • WETH can then be used within DeFi platforms and decentralized applications.
  • To retrieve the original ETH, users can exchange their WETH back through the smart contract.
  • The contract will burn the WETH and return the original ETH to the user.

Oct 24, 2024
Read More
Cheatsheet
solidity

Blockchain Libraries Cheatsheet

and reactive Java and Android library for working with smart contracts and integrating with Ethereum nodes.

  • Use Cases:
  • Build Ethereum-based applications in Java and Android.
  • Interact with smart contracts and Ethereum nodes.
  • Send transactions, query blockchain data, and manage Ethereum accounts.
  • Key Features:
  • Full support for Ethereum JSON-RPC.
  • Asynchronous and synchronous execution of requests.
  • Built-in support for Solidity smart contract wrappers.
  • Installation:

Aug 23, 2024
Read More
Cheatsheet
solidity

Blockchain Development Tools, Libraries, and Frameworks Cheatsheet

  • Description: A decentralized protocol for indexing and querying blockchain data.
  • Key Features:
  • Allows DApps to query blockchain data efficiently using GraphQL.
  • Supports indexing of data across multiple blockchains.
  • Enables fast and reliable access to blockchain data for DApps.
  • Integrates with Ethereum and IPFS.
  • Website: The Graph
  • Description: A personal Ethereum blockchain used for testing smart contracts and DApps.
  • Key Features:
  • Instant mining of transactions.
  • Detailed logging of all blockchain events.
  • Configurable block intervals and gas limits.
  • Support for both CLI and GUI versions.
  • Website: Ganache

Aug 23, 2024
Read More
Tutorial
solidity

Writing an ERC-20 Token Contract with OpenZeppelin

Creating your own ERC-20 token is one of the most common tasks in Ethereum smart contract development. The ERC-20 standard defines a set of rules that all Ethereum tokens must follow, ensuring compatibility with existing applications like wallets, exchanges, and more. OpenZeppelin provides a robust, secure, and widely-used library of smart contract components that simplify the process of creating an ERC-20 token. In this tutorial, we will guide you through the steps to create and deploy your own ERC-20 token using OpenZeppelin.

Before you begin, make sure you have the following:

Aug 22, 2024
Read More
Cheatsheet
solidity

Solidity Cheatsheet

function multiply(uint a, uint b) public pure returns (uint) {
    uint result;
    assembly {
        result := mul(a, b)
    }
    return result;
}

  • Use memory over storage for temporary variables.

Aug 22, 2024
Read More
Tutorial
solidity

Understanding Gas and Optimization in Smart Contracts

2. Use view and pure Functions

  • Functions declared with view or pure keywords do not modify the blockchain state and therefore do not consume gas when called externally (only when called by other contracts).
  • Example: Use view functions for read-only operations, such as retrieving data from a contract.

Aug 22, 2024
Read More
Tutorial
solidity

Building a Decentralized Application (DApp) with Smart Contracts

Now that the smart contract is deployed, let’s create a front-end interface to interact with it. We’ll use HTML, JavaScript, and Web3.js to build a simple web page that allows users to set and retrieve the message stored in the contract.

Example Front-End Code:

Aug 22, 2024
Read More
Tutorial
solidity

Introduction to Smart Contracts on Ethereum

  • Switch to the "Deploy & Run Transactions" tab.
  • Select "Injected Web3" as the environment to connect to MetaMask.
  • Choose a test network like Ropsten or Kovan in MetaMask.
  • Click "Deploy" and confirm the transaction in MetaMask.
  • Once deployed, the contract will appear in the "Deployed Contracts" section.
  • You can now call the set and get functions to interact with your contract.

Aug 22, 2024
Read More
Tutorial
javascript solidity

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

Compile the contract using Truffle:

truffle compile

Aug 20, 2024
Read More
Tutorial
python

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

   def close_order(order_id, symbol):
       response = session.cancel_active_order(order_id=order_id, symbol=symbol)
       if response['ret_code'] == 0:
           print(f"Order {order_id} closed successfully.")
       else:
           print(f"Error closing order: {response['ret_msg']}")
       return response

   close_order('order_id_here', 'BTCUSD')  # Replace with your actual order ID

Replace 'order_id_here' with the actual order ID you want to close.

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

Introduction

In this tutorial, we'll learn how to track a specific Solana address for new trades and notify via console.log with the transaction details, including the amount bought or sold. We will use the Solana Web3.js library to connect to the Solana blockchain, listen for new transactions, and fetch their details.

Aug 09, 2024
Read More
Tutorial
javascript nodejs

Tracking Newly Created Tokens on Solana

node index.js

Conclusion

Aug 09, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!