Txn hash not found on native: /block . How to get smart contract creator

Hi admin,

First of all, thanks for letting me into this forum.

I was looking for detail txn hash in bsc mainnet using native: /block . Detail info:

  1. contract address: 0xb1035523a844371c2877f8a3b2f2f8d337403b6f
  2. block number: 8242108

I want to to retrieve “from_address” [contract creator] in the txn hash.

Unfortunately the json response does not contain txn in block# i was looking for.

Any idea?

Or alternative finding contract creator using other methods?

Thank you!

1 Like

Hey @edi.msi

Why do you want to get info from block 8242108 if the contract has been created at 7954300?

1 Like

If you will call /block for 8242108 you will see several transactions with 0xb1035523a844371c2877f8a3b2f2f8d337403b6f contract.

You need to find the transaction which has a topic 0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0 - it’s a topic OwnershipTransferred.

And from that transaction you need to get “from_address”:

Hope this will help you :man_mechanic:

Hi @Yomoo thank you for your response.

I got block# 8242108 from Token: /erc20/metadata. From there I put the block number into Native: /block, unfortunately could not find the contract address.

Did you find 7954300 from metadata as well?

If all you want is to know its contract creator, you can search that contract on bsccan: https://bscscan.com/address/0xb1035523a844371c2877f8a3b2f2f8d337403b6f and you’ll find that info at More Info

Or you want to be able to do it programmatically for any contract?

Hey @edi.msi

Metadata doesn’t show creation block.

7954300 - I’ve found on bscscan.

One possible solution - is to check contract event OwnershipTransferred. The first event = contract creation:

const ABI = {
  "anonymous": false,
  "inputs": [
    {
      "indexed": true,
      "internalType": "address",
      "name": "previousOwner",
      "type": "address"
    },
    {
      "indexed": true,
      "internalType": "address",
      "name": "newOwner",
      "type": "address"
    }
  ],
  "name": "OwnershipTransferred",
  "type": "event"
};
const options = {
  chain: "bsc",
  address: "0xb1035523a844371c2877f8a3b2f2f8d337403b6f",
  topic: "0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0",
  abi: ABI 
};
const events = await Moralis.Web3API.native.getContractEvents(options);
const eventsArray = events.result;
const firstEvent = eventsArray[eventsArray.length - 1];
const contractCreator = firstEvent.data.newOwner;

image

2 Likes

Usually the contract has a small amount of this event, so there shouldn’t be any problems.

This method of determining the creator of the contract is suitable for all ERC20 tokens.

i see. the original idea is to fetch contract creator with just given single contract address using what Moralis has in Web3api.

without opening bscscan @cryptokid.

how do i check event OwnershipTransferred using Moralis @Yomoo?