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, 
    "disable_total": True, 
}
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”
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 (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_date str 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.
    ””
offset int offset     0
limit int The desired page size of the result.     0
disable_total bool If the result should skip returning the total count (Improves performance).   True True

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", 
    "chain": "eth", 
    "block_number": "", 
    "from_block": "", 
    "to_block": "", 
    "from_date": "", 
    "to_date": "", 
    "topic0": "", 
    "topic1": "", 
    "topic2": "", 
    "topic3": "", 
    "limit": 0, 
    "disable_total": True, 
    "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”
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”
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 (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_date str 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
    ””
topic0 str topic0     ””
topic1 str topic1     ””
topic2 str topic2     ””
topic3 str topic3     ””
limit int The desired page size of the result.     0
disable_total bool If the result should skip returning the total count (Improves performance).   True True
cursor str The cursor returned in the previous response (used for getting the next page).     ””