Skip to main content

Get logs by contract

GEThttps://deep-index.moralis.io/api/v2/:address/logs

Get the logs for a contract.

PATH PARAMS
addressstringrequired
The address of the contract
QUERY PARAMS
chainstring
The chain to query
block_numberstring

The block number

  • Provide the param 'block_numer' or ('from_block' and / or 'to_block')
  • If 'block_numer' is provided in combination with 'from_block' and / or 'to_block', 'block_number' will will be used
from_blockstring

The minimum block number from which to get the logs

  • Provide the param 'block_numer' or ('from_block' and / or 'to_block')
  • If 'block_numer' is provided in combination with 'from_block' and / or 'to_block', 'block_number' will will be used
to_blockstring

The maximum block number from which to get the logs

  • Provide the param 'block_numer' or ('from_block' and / or 'to_block')
  • If 'block_numer' is provided in combination with 'from_block' and / or 'to_block', 'block_number' will will be used
from_datestring

The start date from which to get the logs (any format that is accepted by momentjs)

  • Provide the param 'from_block' or 'from_date'
  • If 'from_date' and 'from_block' are provided, 'from_block' will be used.
  • If 'from_date' and the block params are provided, the block params will be used. Please refer to the blocks params sections (block_number,from_block and to_block) on how to use them
to_datestring

Get the logs up to this date (any format that is accepted by momentjs)

  • Provide the param 'to_block' or 'to_date'
  • If 'to_date' and 'to_block' are provided, 'to_block' will be used.
  • If 'to_date' and the block params are provided, the block params will be used. Please refer to the blocks params sections (block_number,from_block and to_block) on how to use them
topic0string
topic0
topic1string
topic1
topic2string
topic2
topic3string
topic3
limitnumber
The desired page size of the result.
disable_totalboolean
If the result should skip returning the total count (Improves performance).
cursorstring
The cursor returned in the previous response (used for getting the next page). Learn more on cursor pagination here.
Responses
API KEY
import Moralis  from 'moralis';
import { EvmChain } from '@moralisweb3/evm-utils';

try {
const address = '0x1234567890123456789012345678901234567890';

const chain = EvmChain.ETHEREUM;

await Moralis.start({
apiKey: 'YOUR_API_KEY',
// ...and any other configuration
});

const response = await Moralis.EvmApi.events.getContractLogs({
address,
chain,
});

console.log(response?.result);
} catch (e) {
console.error(e);
}

Response Example
{
"total": "100",
"page": "1",
"page_size": "100",
"result": {
"transaction_hash": "0x2d30ca6f024dbc1307ac8a1a44ca27de6f797ec22ef20627a1307243b0ab7d09",
"address": "0x057Ec652A4F150f7FF94f089A38008f49a0DF88e",
"block_timestamp": "2021-04-02T10:07:54.000Z",
"block_number": 12526958,
"block_hash": "0x0372c302e3c52e8f2e15d155e2c545e6d802e479236564af052759253b20fd86",
"data": "0x00000000000000000000000000000000000000000000000de05239bccd4d537400000000000000000000000000024dbc80a9f80e3d5fc0a0ee30e2693781a443",
"topic0": "0x2caecd17d02f56fa897705dcc740da2d237c373f70686f4e0d9bd3bf0400ea7a",
"topic1": "0x000000000000000000000000031002d15b0d0cd7c9129d6f644446368deae391",
"topic2": "0x000000000000000000000000d25943be09f968ba740e0782a34e710100defae9",
"transaction_index": 12,
"log_index": 15
}
}