Moralis-Python-SDK

events API:

evm_api.events


get_contract_events

evm_api.events.get_contract_events()

Get events for a contract ordered by block number in descending order. Try it with Swagger.

Example

from moralis import evm_api

api_key = "YOUR_API_KEY"
params = {
    "address": "", 
    "topic": "", 
    "chain": "eth", 
    "from_block": 0, 
    "to_block": 0, 
    "from_date": "", 
    "to_date": "", 
    "offset": 0, 
    "limit": 0, 
    "order": "DESC", 
    "cursor": "", 
}
body = ""

result = evm_api.events.get_contract_events(
    api_key=api_key,
    params=params,
    body=body,
)

print(result)

Parameters

Name Type Description Required Default Example
address str The address of the contract Yes   ””
topic str The topic of the event Yes   ””
chain enum[str]:
- “eth”
- “0x1”
- “goerli”
- “0x5”
- “sepolia”
- “0xaa36a7”
- “polygon”
- “0x89”
- “mumbai”
- “0x13881”
- “bsc”
- “0x38”
- “bsc testnet”
- “0x61”
- “avalanche”
- “0xa86a”
- “fantom”
- “0xfa”
- “palm”
- “0x2a15c308d”
- “cronos”
- “0x19”
- “arbitrum”
- “0xa4b1”
- “chiliz”
- “0x15b38”
- “chiliz testnet”
- “0x15b32”
- “gnosis”
- “0x64”
- “gnosis testnet”
- “0x27d8”
- “base”
- “0x2105”
- “base testnet”
- “0x14a33”
- “base sepolia”
- “0x14a34”
- “optimism”
- “0xa”
- “holesky”
- “0x4268”
- “polygon amoy”
- “0x13882”
- “linea”
- “0xe708”
- “moonbeam”
- “0x504”
- “moonriver”
- “0x505”
- “moonbase”
- “0x507”
The chain to query   “eth” “eth”
from_block int 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.
    0
to_block int 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.
    0
from_date str The start date from which to get the logs (format in seconds or datestring 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_date str Get the logs up to this date (format in seconds or datestring accepted by momentjs)
* Provide the param ‘to_block’ or ‘to_date’
* If ‘to_date’ and ‘to_block’ are provided, ‘to_block’ will be used.
    ””
offset int offset     0
limit int The desired page size of the result.     0
order enum[str]:
- “ASC”
- “DESC”
The order of the result, in ascending (ASC) or descending (DESC)   “DESC” “DESC”
cursor str The cursor returned in the previous response (used for getting the next page).     ””

Body

Type Description Required
object ABI of the specific event Yes

get_contract_logs

evm_api.events.get_contract_logs()

Get the logs for a contract.

Example

from moralis import evm_api

api_key = "YOUR_API_KEY"
params = {
    "address": "0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB", 
    "topic0": "", 
    "chain": "eth", 
    "block_number": "", 
    "from_block": "", 
    "to_block": "", 
    "from_date": "", 
    "to_date": "", 
    "limit": 0, 
    "order": "DESC", 
    "cursor": "", 
}

result = evm_api.events.get_contract_logs(
    api_key=api_key,
    params=params,
)

print(result)

Parameters

Name Type Description Required Default Example
address str The address of the contract Yes   “0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB”
topic0 str topic0 Yes   ””
chain enum[str]:
- “eth”
- “0x1”
- “goerli”
- “0x5”
- “sepolia”
- “0xaa36a7”
- “polygon”
- “0x89”
- “mumbai”
- “0x13881”
- “bsc”
- “0x38”
- “bsc testnet”
- “0x61”
- “avalanche”
- “0xa86a”
- “fantom”
- “0xfa”
- “palm”
- “0x2a15c308d”
- “cronos”
- “0x19”
- “arbitrum”
- “0xa4b1”
- “chiliz”
- “0x15b38”
- “chiliz testnet”
- “0x15b32”
- “gnosis”
- “0x64”
- “gnosis testnet”
- “0x27d8”
- “base”
- “0x2105”
- “base testnet”
- “0x14a33”
- “base sepolia”
- “0x14a34”
- “optimism”
- “0xa”
- “holesky”
- “0x4268”
- “polygon amoy”
- “0x13882”
- “linea”
- “0xe708”
- “moonbeam”
- “0x504”
- “moonriver”
- “0x505”
- “moonbase”
- “0x507”
The chain to query   “eth” “eth”
block_number str 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_block str 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_block str 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_date str The start date from which to get the logs (format in seconds or datestring 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_date str Get the logs up to this date (format in seconds or datestring 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
    ””
limit int The desired page size of the result.     0
order enum[str]:
- “ASC”
- “DESC”
The order of the result, in ascending (ASC) or descending (DESC)   “DESC” “DESC”
cursor str The cursor returned in the previous response (used for getting the next page).     ””