Contract Events
You can listen to events that are emitted by a contract.
This is useful when you want real-time updates of events happening on the blockchain.
The names of the events are the same as the events emitted from the smart contract.
For prebuilt contracts, you can inspect the source code to see the events that are emitted in each function call.
Below are some examples:
Event Name | Description | Source Code |
---|---|---|
TokensClaimed | Token claimed by a wallet from a Drop contract | Smart Contract Code |
TokensMinted | Token minted by a wallet into a NFT / Token contract | Smart Contract Code |
ListingAdded | New listing created in a marketplace contract | Smart Contract Code |
Get All Past Events
Fetch all historical events emitted by the contract.
- React
- Javascript
- Python
- Go
- Unity
// Optionally pass in filters to limit the blocks from which events are retrieved
const filters = {
fromBlock: 0,
toBlock: 1000000,
}
const events = await contract.events.getAllEvents(filters);
console.log(events[0].eventName);
console.log(events[0].data);
// Optionally pass in filters to limit the blocks from which events are retrieved
const filters = {
fromBlock: 0,
toBlock: 1000000,
}
const events = await contract.events.getAllEvents(filters);
console.log(events[0].eventName);
console.log(events[0].data);
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Unity SDK Reference for more information.
Reach out on Discord for further assistance!
Listen to a Specific Event
Fetch specific historical events emitted by the contract.
- React
- Javascript
- Python
- Go
- Unity
// The name of the event to get logs for
const eventName = "Transfer";
// Optionally pass in options to limit the blocks from which events are retrieved
const options = {
fromBlock: 0,
toBlock: 1000000, // can also pass "latest"
order: "desc",
// Configure event filters (filter on indexed event parameters)
filters: {
from: "0x...",
to: "0x..."
}
};
const events = await contract.events.getEvents(eventName, options);
console.log(events[0].eventName);
console.log(events[0].data);
// The name of the event to get logs for
const eventName = "Transfer";
// Optionally pass in options to limit the blocks from which events are retrieved
const options = {
fromBlock: 0,
toBlock: 1000000, // can also pass "latest"
order: "desc",
// Configure event filters (filter on indexed event parameters)
filters: {
from: "0x...",
to: "0x..."
}
};
const events = await contract.events.getEvents(eventName, options);
console.log(events[0].eventName);
console.log(events[0].data);
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
// First we define a filter to only get Transfer events where the "from" address is "0x..."
// Note that you can only add filters for indexed parameters on events
filters := map[string]interface{} {
"from": common.HexToAddress("0x...")
}
// Now we can define the query options, including the block range and the filter
queryOptions := thirdweb.EventQueryOptions{
FromBlock: 100000000, // Defaults to block 0 if you don't specify this field
ToBlock: 100000001, // Defaults to latest block if you don't specify this field
Filters: filters,
}
// Now we can query for the Transfer events
events, _ := contract.Events.GetEvents("Transfer", queryOptions)
This feature is missing a code snippet or might not be supported yet.
Check the Unity SDK Reference for more information.
Reach out on Discord for further assistance!
Listen to All Events
Listen to all events emitted by the contract.
- React
- Javascript
- Python
- Go
- Unity
contract.events.listenToAllEvents((event) => {
console.log(event.eventName) // the name of the emitted event
console.log(event.data) // event payload
}
contract.events.listenToAllEvents((event) => {
console.log(event.eventName) // the name of the emitted event
console.log(event.data) // event payload
}
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Unity SDK Reference for more information.
Reach out on Discord for further assistance!
Listen to a Specific Event
Listen to all occurrences of a specific event.
- React
- Javascript
- Python
- Go
- Unity
contract.events.addEventListener("TokensMinted", (event) => {
console.log(event);
});
contract.events.addEventListener("TokensMinted", (event) => {
console.log(event);
});
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
// Define a listener function to be called whenever a new Transfer event is received
listener := func (event thirdweb.ContractEvent) {
fmt.Printf("%#v\n", event)
}
// Add a new listener for the Transfer event
subscription := contract.Events.AddEventListener(context.Background(), "Transfer", listener)
// Unsubscribe from the Transfer event at some time in the future, closing the listener
subscription.Unsubscribe()
This feature is missing a code snippet or might not be supported yet.
Check the Unity SDK Reference for more information.
Reach out on Discord for further assistance!
Listen to Transactions
Listen to all transactions in their raw form.
- React
- Javascript
- Python
- Go
- Unity
contract.events.addTransactionListener((event) => {
console.log(event);
}
contract.events.addTransactionListener((event) => {
console.log(event);
}
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Unity SDK Reference for more information.
Reach out on Discord for further assistance!
Remove All Listeners
- React
- Javascript
- Python
- Go
- Unity
contract.events.removeAllListeners();
contract.events.removeAllListeners();
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Unity SDK Reference for more information.
Reach out on Discord for further assistance!
Remove an Event Listener
- React
- Javascript
- Python
- Go
- Unity
contract.events.removeEventListener("TokensMinted", (event) => {
console.log(event);
});
contract.events.removeEventListener("TokensMinted", (event) => {
console.log(event);
});
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Unity SDK Reference for more information.
Reach out on Discord for further assistance!
Remove a Transaction Listener
- React
- Javascript
- Python
- Go
- Unity
contract.events.removeTransactionListener((event) => {
console.log(event);
}
contract.events.removeTransactionListener((event) => {
console.log(event);
}
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Unity SDK Reference for more information.
Reach out on Discord for further assistance!