Tuesday, July 8, 2025
The Dao Makers
No Result
View All Result
CRYPTO MARKETCAP
  • Home
  • Bitcoin
  • Launchpads
  • Crypto Updates
    • General
    • Blockchain
    • Ethereum
    • Altcoin
    • Mining
    • Crypto Exchanges
  • NFT
  • DeFi
  • Web3
  • Metaverse
  • Analysis
  • Regulations
  • Scam Alert
  • Videos
  • Home
  • Bitcoin
  • Launchpads
  • Crypto Updates
    • General
    • Blockchain
    • Ethereum
    • Altcoin
    • Mining
    • Crypto Exchanges
  • NFT
  • DeFi
  • Web3
  • Metaverse
  • Analysis
  • Regulations
  • Scam Alert
  • Videos
No Result
View All Result
The Dao Makers
No Result
View All Result

Get Contract Logs – Exploring Web3 Get Event Logs for Ethereum

by The Dao Makers
January 2, 2023
in Web3
Reading Time: 12 mins read
0 0
A A
0
Home Web3
Share on FacebookShare on Twitter


With Moralis‘ industry-leading occasions API (a.okay.a. EVM API), you will get any ETH contract logs in a matter of seconds! With this software programming interface, all you want is a single API name to the “getContractLogs” endpoint whereas passing a wise contract handle as an argument:

const response = await Moralis.EvmApi.occasions.getContractLogs({
handle: question.handle,
chain: question.chain,
});

By familiarizing your self with the Web3 growth house and the occasions API, you’ll be able to seamlessly get ETH occasion logs and combine them into any of your future blockchain initiatives very quickly. For extra details about the ”getContractLogs” endpoint, take a look at Moralis’ official get logs by contract documentation web page! Furthermore, if you have already got an energetic Moralis account, go forward and soar straight into the documentation web page to make the most of the code snippet above. Nevertheless, should you’re new to Moralis, enroll and observe our lead as we discover methods to make the most of the code snippet on this article!

Overview

When constructing typical Web2 initiatives, purposes and web sites generally use logs to seize and describe occasions occurring at sure moments. Builders can, in flip, use these logs to detect occasions, debug code, notify log viewers of occurrences, and many others. Moreover, logs play an equally vital function throughout the Web3 growth house when writing or interacting with sensible contracts. In case you’d prefer to discover logs and occasions additional for Web3, this text will present you methods to simply get contract logs utilizing Moralis! 

Together with a tutorial on methods to get contract logs, the article initially begins by exploring the intricacies of Ethereum logs. From there, we’ll dive into ETH get logs strategies and uncover the place the occasion logs are saved earlier than leaping into the tutorial! 

Now, should you’d prefer to discover matters past contract logs, it’s best to take a look at extra thrilling content material right here at Moralis. As an example, take a look at our information to ethers.js occasions or discover ways to hearken to sensible contract occasions utilizing ethers.js! Furthermore, to be able to observe alongside in the course of the “Web3 get occasion logs tutorial” a part of this text, be sure that to enroll with Moralis. Creating an account is completely free, and it solely takes a few seconds, so you don’t have anything to lose! 

What are Ethereum Contract Logs? 

Earlier than exhibiting you methods to get contract logs utilizing Moralis, we have to initially cowl what Ethereum contract logs are and the way they are often useful. As such, with out additional ado, let’s kickstart this tutorial by answering the query, ”what are Ethereum contract logs?”.

illustrative Ethereum globe surrounded by elements such as contract logs

Ethereum sensible contracts can usually emit occasions each time they execute and carry out sure on-chain actions. When this happens, the contracts additionally create Ethereum contract logs, offering perception into specific occasions. As such, each time transactions are mined, you’ll be able to view occasion logs associated to those transactions by querying the Ethereum blockchain. 

Furthermore, Ethereum occasion logs include two central elements: matters and knowledge. As such, allow us to rapidly break down the 2 under, beginning with matters: 

Subjects – The preliminary a part of Ethereum occasion logs is an array of matters, that are 32-byte ”phrases” describing the main points of an occasion. Additional, every log can have a most quantity of 4 matters.  Information – The opposite element of Ethereum occasion logs is extra knowledge. A log’s matters and knowledge work greatest collectively as these elements have their very own advantages and downsides. For instance, the matters are searchable, however the knowledge isn’t. Nevertheless, together with knowledge in Ethereum occasion logs is rather more economically pleasant than matters. 

However, if you would like a extra complete breakdown, take a look at our article exploring Ethereum logs in additional element! 

What are ETH Get Logs, and The place are They Saved?  

With a extra profound understanding of Ethereum occasion logs, this part will discover ETH get logs strategies after which take a better take a look at the place the logs are saved. As such, allow us to begin by taking a better take a look at ETH get logs strategies within the following sub-section.

ETH Get Logs 

So what are ETH get logs? ETH get logs are strategies for querying occasion logs from the Ethereum blockchain. There are numerous Web3 get occasion logs strategies provided by a large number of blockchain infrastructure corporations and node suppliers. Nevertheless, this text will give attention to your best choice, Moralis’ ”getContractLogs” endpoint!

The ”getContractLogs” endpoint is the most effective and most accessible ETH get logs technique, enabling you to question Ethereum occasion logs by means of a single API name. All you might want to do is provide a contract handle and name this endpoint. 

What’s extra, you’ll be able to check out this ETH get logs technique by visiting Moralis’ official get logs by contract documentation web page, and it’ll look one thing like this: 

get logs by contract documentation page showing the get contract logs endpoint

From there, to check this Web3 get occasion logs technique, provide an handle within the ”handle” enter area and hit the ”Strive It!” button:  

address parameter and the get event logs for ethereum try it out button

However, now that you’ve familiarized your self with Moralis’ ETH get logs technique, allow us to briefly take a better take a look at the place Ethereum occasion logs are saved earlier than exhibiting you methods to get contract logs in the primary a part of the tutorial!

The place are They Saved? 

When Ethereum sensible contracts emit occasions, logs are written and saved in a transaction receipt. All receipts include transaction outcomes comprising two core components: Ethereum occasion logs and standing. As such, together with the occasion logs, transaction receipts additionally include data corresponding to log blooms, gasoline used for the transaction, and many others. 

physical receipt illustrating ETH get logs

In conclusion, transaction receipts retailer Ethereum occasion logs together with different transaction knowledge. However, now that you understand the place they’re saved, allow us to dive into the central a part of this Web3 get occasion logs tutorial and present you methods to get contract logs with Moralis! 

Web3 Get Occasion Logs Tutorial – Find out how to Get Contract Logs with Moralis’ ETH Get Logs Technique

Now that you understand what Ethereum occasion logs are and what they can be utilized for, allow us to soar straight right into a sensible Web3 get occasion logs instance. The next sections will present you methods to create a NodeJS and NextJS software for querying the occasion logs of any Ethereum sensible contract. Extra particularly, the data returned to the app’s person interface (UI) will include knowledge, corresponding to a transaction time stamp, block quantity, contract handle, and transaction hash. 

Moralis

To make this tutorial as simple as potential, we’ll use Moralis’ occasions API and the ”getContractLogs” endpoint. What’s extra, because of the general accessibility of Moralis, it is possible for you to to create this software in three steps:

Cloning and Setting Up the ProjectCode Breakdown: BackendCode Breakdown: Frontend

In case you want watching movies to study, take a look at the clip under from the Moralis YouTube channel. On this video, considered one of our software program engineers walks you thru the aforementioned steps, offering an much more in-depth breakdown of the code: 

However, earlier than leaping into step one of this get contract logs tutorial, allow us to take a better take a look at the tip product with a fast software demo! 

Get Contract Logs: Software Demo – What are You Working Towards? 

To start with, allow us to briefly take a better take a look at the tip consequence. Doing so offers you a extra profound understanding of what you’re working towards. However, you could find a print display screen of the app’s touchdown web page down under: 

landing page of our get contract logs decentralized application

Because the picture illustrates, the UI consists of 4 core components: a heading, two enter fields, and a ”Submit” button. To make use of the appliance, you might want to provide an Ethereum sensible contract handle, choose a sequence utilizing the ”Choose Chain” drop-down menu, and hit the button. When you click on on the button, the appliance calls the ”getContractLogs” Moralis endpoint to fetch and show the contract’s occasion logs: 

result from a Web3 get event logs call using our dapp

As you’ll be able to see from the responses above, the app shows every occasion’s timestamp, block quantity, contract handle, and transaction hash.

If this sounds thrilling and also you wish to discover ways to create this software, learn on as we’ll cowl the method from begin to end. With out additional ado, allow us to soar into step one, the place we’ll present you methods to clone and arrange the undertaking! 

Step 1: Web3 Get Occasion Logs – Cloning and Setting Up the Mission 

Since this can be a tutorial made primarily to indicate you methods to get the Ethereum occasion logs of a contract, we’ll use an already ready software template, permitting us to do exactly that. As such, we are able to skip redundancies related to creating the app and give attention to the core performance of querying Ethereum occasion logs. 

To start with, launch your IDE. Then, create a NodeJS undertaking folder and clone the appliance to your native listing. You’ll find the GitHub repository for the whole undertaking down under: 

Full Get Contract Logs App Documentation – https://github.com/MoralisWeb3/youtube-tutorials/tree/major/get-contract-logs 

From there, launch a brand new terminal and set up the required dependencies by working the next command: 

npm i moralis @moralisweb3/common-evm-utils dotenv specific

With the dependencies put in, you need to add your Moralis API key to the ”backend” folder. To take action, begin by making a ”.env” file within the ”backend” root folder and create the next setting variable: 

MORALIS_API_KEY = “replace_me”

Nevertheless, as you may need figured, you need to change ”replace_me” together with your precise key. Now, to be able to get a key, you want a Moralis account. So, should you do not need an account already, enroll with Moralis immediately and log in. From there, one can find your key underneath the ”Web3 APIs” tab: 

Web3 API landing page from Moralis

After you have added your key to the code, you might have accomplished the setup and the tutorial’s preliminary step. Because of this, it’s best to now be capable to launch the appliance. Nevertheless, to offer perception into the appliance’s internal workings, the next two steps will break down the important components of the code, beginning with the backend! 

Step 2: Web3 Get Occasion Logs – Code breakdown: Backend 

This part will break down the code for the ”index.js” file, as that is the place we discover many of the backend logic. To start with, on the preliminary strains of ”index.js”, we require the mandatory dependencies: 

const specific = require(“specific”);
const app = specific();
const port = 5001;
const Moralis = require(“moralis”).default;
const cors = require(“cors”);

require(“dotenv”).config({ path: “.env” });

app.use(cors());
app.use(specific.json());

From there, we create a brand new ”MORALIS_API_KEY” variable by importing the important thing you only recently added to the ”.env” file: 

const MORALIS_API_KEY = course of.env.MORALIS_API_KEY;

Subsequent, we add the ”/getlogs” endpoint, the place we discover the logic for querying the Ethereum occasion logs. As you’ll be able to see within the snippet under, we name the ”getContractLogs” endpoint by passing the handle and chain from the frontend as arguments: 

app.get(“/getlogs”, async (req, res) => {
strive {
const { question } = req;

const response = await Moralis.EvmApi.occasions.getContractLogs({
handle: question.handle,
chain: question.chain,
});

return res.standing(200).json(response);
} catch (e) {
console.log(`One thing went unsuitable ${e}`);
return res.standing(400).json();
}
});

This clearly illustrates the facility of Moralis! All you want is a single API name to get the Ethereum occasion logs of any sensible contract! 

Lastly, to high issues off, we initialize Moralis utilizing the API key by working the ”Moralis.begin()” operate: 

Moralis.begin({
apiKey: MORALIS_API_KEY,
}).then(() => {
app.pay attention(port, () => {
console.log(`Listening for API Calls`);
});
});

That covers the backend logic. Allow us to dive into the frontend code to see the way it all ties collectively!

Step 3: Web3 Get Occasion Logs – Code breakdown: Frontend 

It is possible for you to to search out the entire frontend logic within the ”major.js” file of the ”frontend” folder. On this case, we’ll primarily give attention to ”handleSubmit()” since that is the place we discover the frontend performance for getting the Ethereum occasion logs. Earlier than launching the app, be sure that to put in “axios” within the “frontend” root folder. To take action, use this terminal enter: “npm i axios”. All in all, the operate seems to be like this: 

const handleSubmit = async () => {
handle = doc.querySelector(“#inputField”).worth;
const chain = chainValue.worth;

const response = await axios.get(`http://localhost:5001/getlogs`, {
params: { handle, chain },
});

console.log(response.knowledge);
setResult(response.knowledge.consequence);
setShowResult(true);
doc.querySelector(“#inputField”).worth = “”;
setChainValue(“”);
};

The operate above known as each time somebody clicks on the ”Submit” button on the app’s UI. As soon as referred to as, the operate extracts the values from the 2 enter fields, saving them within the ”handle” and ”chain” variables. 

From there, the operate makes an “axios” request to the ”/getlogs” endpoint of your backend server, passing the ”handle” and ”chain” variables as arguments. As you keep in mind from the backend code, this endpoint, in flip, calls the ”getContractLogs” Moralis endpoint, returning the Ethereum occasion logs, that are lastly saved within the ”response” object. 

That covers the ”handleSubmit()” operate! The rest of the code handles the required imports, renders the UI components, maps the outcomes utilizing the information from the ”response” object, and many others. 

Furthermore, word that the data on the UI is just a choice of the information supplied by the ”getContractLogs” endpoint. For extra particulars, take a look at the get logs by contract documentation web page. 

That covers this get contract logs tutorial and the sensible instance. When you have adopted alongside this far, now you can apply the identical elementary rules in future growth endeavors to get contract logs and use the information straight in your Web3 initiatives! 

Abstract – Find out how to Get Contract Logs with Moralis’ ETH Get Logs Technique

This text taught you methods to get contract logs utilizing Moralis’ occasions API and the ”getContractLogs” endpoint. Extra particularly, we confirmed you methods to create an software from which you might constantly get the logs of any sensible contracts by supplying its handle. Because of the accessibility of Moralis, you have been capable of create the app in solely three steps: 

Cloning and Setting Up the ProjectCode Breakdown: BackendCode Breakdown: Frontend

When you have joined us till this level, you now know methods to get contract logs utilizing Moralis. From right here, you’ll be able to apply your new abilities to any future blockchain initiatives to implement related performance! 

In case you discovered this Web3 programming tutorial instructive, take into account trying out extra guides right here on the Moralis Web3 weblog. As an example, take a look at our article answering the query, ”what’s danksharding?”, discover ways to construct an ethers.js dapp, or uncover methods to use a Web3 JS name contract operate! 

Furthermore, in case you are severe about turning into a Web3 developer, enroll with Moralis now. With Moralis’ Web3 APIs, you’ll be able to absolutely leverage the facility of blockchain know-how to construct dapps extra seamlessly! 



Source link

Tags: ContractethereumEventExploringLogsWeb3
Previous Post

Bitcoin miner revenue down 37.5% in 2022 YoY

Next Post

Peter Schiff Says Get Ready For Worse Inflation, What Does This Mean For Bitcoin?

Related Posts

Web3

Let’s use Web3 to grow projects that fight climate change

July 1, 2025
Web3

Binance introduces self-custody Web3 wallet

July 2, 2025
Web3

What we can learn from the demise of Reddit crypto rewards

July 2, 2025
Web3

SBF convicted on all charges, Hong Kong buzzes with Web3 events

July 2, 2025
Web3

Web2 social media is failing its users. Web3 can do better

July 3, 2025
Web3

Mastercard explores partnerships with crypto wallets MetaMask, Ledger: CoinDesk

July 3, 2025
Next Post

Peter Schiff Says Get Ready For Worse Inflation, What Does This Mean For Bitcoin?

A Crypto Holiday Special: Past, Present, And Future With Ben Lilly

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Trending
  • Comments
  • Latest

Latest Week in Ethereum News : ethereum

December 17, 2022

Adecoagro Partners With Tether to Pioneer Renewable Energy Use for Bitcoin Mining in Brazil

July 4, 2025

5 Generations, 1 Team — Heres How to Lead a Multigenerational Workforce

July 7, 2025

🦄 uniswap-universal-router-decoder ✨ v0.8.0 ✨ has just been released !!

March 18, 2023

The four times Bitcoin price fell by Independence Day each year

July 4, 2025

Shenzhen warns citizens of investment scams using stablecoins

July 7, 2025

SELL ALTCOINS NOW? | BITCOIN | CRYPTO NEWS BANGLA | BULL RUN | ALTSEASON | MARKET

37

Why Facebook-Parent Meta Is Willing To Lose Billions On The Metaverse

46

BTC Price Predictions, SUI Fall, HYPE, Trump Coin Scandal & More

42

Game Changer: SEC Streamlines Path for Crypto ETFs

July 8, 2025

The Smarter Web Company Acquires 226.42 Bitcoin, Total Holdings Reach 1,000 BTC

July 8, 2025

Bonk Eyes 1M Holders, plans to Burn 1 Trillion Tokens in Major Milestone Move

July 8, 2025

60 Crypto Operators Under Ukraine’s Gun

July 8, 2025

Ethereum Price Hits Support – Can It Launch a Fresh Move Higher?

July 8, 2025

Ripple CTO Makes Major Revelations: Early XRP Entry, Mined Bitcoins — Here’s The Details

July 8, 2025
Telegram Twitter TikTok Youtube RSS
The Dao Makers

Find the latest Bitcoin, Ethereum, blockchain, crypto, Business, Fintech News, interviews, and price analysis at The Dao Makers.

CATEGORIES

  • Altcoin
  • Analysis
  • Bitcoin
  • Blockchain
  • Crypto Exchanges
  • Crypto Updates
  • DeFi
  • Ethereum
  • Fix Driver Errors
  • Launchpads
  • Metaverse
  • Mining
  • NFT
  • Regulations
  • Scam Alert
  • Uncategorized
  • Videos
  • Web3

SITE MAP

  • Disclaimer
  • Privacy Policy
  • DMCA
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2022 The Dao Makers.
The Dao Makers is not responsible for the content of external sites.

No Result
View All Result
  • Home
  • Bitcoin
  • Launchpads
  • Crypto Updates
    • General
    • Blockchain
    • Ethereum
    • Altcoin
    • Mining
    • Crypto Exchanges
  • NFT
  • DeFi
  • Web3
  • Metaverse
  • Analysis
  • Regulations
  • Scam Alert
  • Videos

Copyright © 2022 The Dao Makers.
The Dao Makers is not responsible for the content of external sites.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In