Skip to main content

Get events by contract

POSThttps://deep-index.moralis.io/api/v2/:address/events

Get events for a contract ordered by block number in descending order.

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

The minimum block number from which to get the logs

  • Provide the param 'from_block' or 'from_date'
  • If 'from_date' and 'from_block' are provided, 'from_block' will be used.
to_blocknumber

The maximum block number from which to get the logs.

  • Provide the param 'to_block' or 'to_date'
  • If 'to_date' and 'to_block' are provided, 'to_block' 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.
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.
topicstringrequired
The topic of the event
offsetnumber
offset
disable_totalboolean
If the result should skip returning the total count (Improves performance).
limitnumber
The desired page size of the result.
BODY PARAM
jsonrequired
ABI of the specific event
Responses
API KEY
import Moralis  from 'moralis';
import { EvmChain } from '@moralisweb3/evm-utils';

try {
const abi = []; // Add ABI

const address = '0x1234567890123456789012345678901234567890';

const chain = EvmChain.ETHEREUM;

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

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

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

Response Example
{
"total": "",
"page": "",
"page_size": "",
"result": [
{
"transaction_hash": "0x2d30ca6f024dbc1307ac8a1a44ca27de6f797ec22ef20627a1307243b0ab7d09",
"address": "0x18F97EF6B2cbac5CA85b375b7093C4A207340d06",
"block_timestamp": "2021-04-02T10:07:54.000Z",
"block_number": 12526958,
"block_hash": "0x0372c302e3c52e8f2e15d155e2c545e6d802e479236564af052759253b20fd86"
}
]
}