When encountering the "Contract Reverted!" error with the "TooManyTopics" dispatch error while calling the mint function in the OpenBrush PSP37 smart contract, it is likely due to exceeding the limit of event topics that can be written for an event.
Upon searching the source code of the Substrate framework for the error code "TooManyTopics," the following code snippet was found:
// If there are more than `event_topics`, then trap.
if topics.len() > ctx.ext.schedule().limits.event_topics as usize {
return Err(Error::<E::T>::TooManyTopics.into());
}
This code snippet indicates that if the number of topics exceeds the predefined limit of event topics, an error will be returned with the "TooManyTopics" variant. By default, the limit for event topics is set to 4 in the Limits implementation:
impl Default for Limits {
fn default() -> Self {
Self {
event_topics: 4,
globals: 256,
locals: 1024,
parameters: 128,
memory_pages: 16,
// 4k function pointers (This is in count not bytes).
table_size: 4096,
br_table_size: 256,
subject_len: 32,
payload_len: 16 * 1024,
runtime_memory: 1024 * 1024 * 128,
}
}
}
The provided code snippet shows the default values for various limits in the Limits struct, with the event_topics limit set to 4.
To resolve the "TooManyTopics" dispatch error, you need to ensure that the number of topics used in your mint function call does not exceed the limit of 4. Review your code and adjust the number of topics accordingly.


