Get contract creation transaction for any token using either Moralis API or other method

Hey there,

I was wondering if there’s a way to get the metadata for the contract creation transaction, which is usually the first-ever transaction for any given token. The main data I need is the transaction hash. Is this possible through Moralis API archives? If not, what other means are available? Thanks in advance!

You can do something like this:

For example to find this transaction ( that created 0x0990faeff7fa89dd42a4c645b2aba0b209f06fa6 smart contract you can get the logs for this smart contract specific to OwnershipTransferred (index_topic_1 address previousOwner, index_topic_2 address newOwner) event with:

I added as topic0 the topic specific to that OwnershipTransferred function call so that you don’t get all the logs for that smart contract, and as a result you’ll have that exact transaction hash that created that smart contract:

  "total": 1,
  "page": 0,
  "page_size": 500,
  "result": [
      "transaction_hash": "0xcc6e357f503581e71f0e9c3240564916ac4827b7c805848626dd8224bd49a303",
      "address": "0x0990faeff7fa89dd42a4c645b2aba0b209f06fa6",
      "block_timestamp": "2021-10-22T03:37:11.000Z",
      "block_number": "13465110",
      "block_hash": "0x2c1ee487e636ad0b42fb64f78dcf3ddd2269c6bbd351151f28b15f9453927223",
      "data": "0x",
      "topic0": "0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0",
      "topic1": "0x0000000000000000000000000000000000000000000000000000000000000000",
      "topic2": "0x0000000000000000000000005ca6d67b24083e520996546254da58d08726f96c",
      "topic3": null

and you can do the same directly from Moralis SDK with:

const options = {
   address: "0x0990faeff7fa89dd42a4c645b2aba0b209f06fa6",
   chain: "eth",
   topic0: "0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0"

t = await Moralis.Web3API.native.getLogsByAddress(options);
1 Like

There he goes again…saving the world one noob at a time. Thanks a bunch! @cryptokid

1 Like

Hey man, while we’re here on this topic. I was wondering if there’s a way to do something similar (through moralis or otherwise) and get the top wallet holders for any token?
Thanks again.

you can use:

options = {“address”: “0x0990faeff7fa89dd42a4c645b2aba0b209f06fa6”, chain: “eth”}
nftOwners = await Moralis.Web3API.token.getNFTOwners(options)

and then to compute that statistic

“Moralis” seems to be undefined in line 2.
If I understand correctly, awaiting nftOwners would require an async def? So something like this maybe?

async def holders():
    options = {'address': contract_address, chain: chain}
    owners =  await Moralis.Web3API.token.getNFTOwners(options)

the code that I pasted would work in a browser console that is already using Moralis SDK

like having this in a html page header:

        <script src="[email protected]/dist/web3.min.js"></script>
        <script src=""></script>

This one goes over my head lol. I’m not sure I’m following…I’m not currently using a Moralis SDK so is there a simpler way to handle it?

are you using REST apis then for Moralis web3api?

yes sir, I have in the past.

you can use the equivalent of REST api for Moralis.Web3API.token.getNFTOwners then

ok thanks, I’ll try that out and give feedback