How to filter transactions by smart contract Method called


I’m checking this NFT smart contract (I’m checking another one but let’s use this one in my example)
Fat Ape Club:

I’d like to filter only the transactions where a specific Method was called, in particular the Mint one.

E.g. of the address above, click on “Last” to see the oldest transactions, you will notice that the method called in the first 105 transactions is called Gift.

Browse 3-4 pages until you see the first Mint, see:


I’d like to make a list of a given NFT smart contract and fetch only the transactions where a particular method was called, which in my case is “Mint”. See example of such a transaction here:

In Moralis I do a simple call:

    const options = { chain: "eth", address: "0xf3114dd5c5b50a573e66596563d15a630ed359b4", order: "asc", from_block: 13522802 }
    const transactions = await Moralis.Web3API.account.getTransactions(options)
    if (transactions.result) {
        for (const trx of transactions.result) {

Example of trx printed to console:

  hash: '0x67c9841dc8136e974cde1147736289499e79d9a12ff23d70ff917cde8604c741',
  nonce: '11',
  transaction_index: '137',
  from_address: '0x54523e45e76ffe5e6ef2a5a7eb03912a5a43f4f1',
  to_address: '0xf3114dd5c5b50a573e66596563d15a630ed359b4',
  value: '100000000000000000',
  gas: '283645',
  gas_price: '120441470503',
  input: '0xa0712d680000000000000000000000000000000000000000000000000000000000000001',
  receipt_cumulative_gas_used: '9459270',
  receipt_gas_used: '189097',
  receipt_contract_address: null,
  receipt_root: null,
  receipt_status: '1',
  block_timestamp: '2021-10-31T20:29:12.000Z',
  block_number: '13526915',
  block_hash: '0x28297295346bfa646085505a20fcb65f66c02e2439a5f6554b4ae554b976fd49',
  addresses: {
    from_to: [

Then I loop the transactions and print them to console, only to see that they contain really basic information, not even the method called…

2 questions:

  1. how to fetch additional info in the transaction, such in this case the method called? Do I need to fetch it 1 by 1 for each transaction already in the response?
  2. do you think this use case deserves to be added to the moralis API? :wink: (of course I think it does, I can’t imagine to make 10k+ requests to the moralis server only to understand what kind of transaction each transaction is… this should be info returned in the list… can you make this happen?)

and in that transaction you have:

input: '0xa0712d680000000000000000000000000000000000000000000000000000000000000001',

those 8 bytes from both strings are identical, and that is how you identify the method name

1 Like

Wow thanks a lot, I’m impressed by the speed and also by the “hacky” answer :wink:

As you guessed I’m quite new in dapps development… so my followup question is, the function name is always determined by the first 8 bytes or it depends by function?

Thanks a lot, this really helped.

Still I think a service like Moralis should offer a way to filter transactions by function called, or by specifying the input as you explained. So for example if a smart contract has like a huge amount of transactions (imagine people transfer them, put them for sale, cancel the sale etc. it makes easily a huge amount of transactions), but I’m interested only in the mints, or gifts or any particular function (so in some other cases it may be the first 10 characters and so on)…

Returning only what I need and filtering out all the rest from the beginning would be a plus, also because Moralis returns max 500 results…

So far, thanks again, I’ll sure be back with more questions in the following days.

you can use pagination to get more than 500 transactions
usually smart contracts should use events and you can filter on events easily with Moralis (but it looks like this smart contract in particular doesn’t use events)
those 8 first characters are determined by the function name and not the other way around