10

I want to prove that a contract was deployed by a specific address (a factory contract). I have noticed that block explorers such as https://etherscan.io/ list the contract creator. How do they get this information? I cant find any way of getting a contracts creators address from the the etherscan api.

How can I identify the address that deployed a contract?

5
  • 1
    The accepted answer is incorrect. The first incoming transaction to a smart contract address is not the creation transaction. The creation transaction is sent to address '0x0'. The receipt of that transaction has contractAddress set to the address of the new smart contract. The first transaction can't have happened until after it's creation. To find the creator, one must look for the creation transaction, which is the transaction with receipt.contractAddress == address. The accepted answer should be de-selected. Oct 30, 2017 at 11:55
  • @ThomasJayRush can you write an answer so i can accept that one instead?
    – Joe
    Nov 1, 2017 at 20:24
  • Done. I tried to explain both cases--third-party API and directly from the node. Nov 1, 2017 at 22:54
  • this question still has no answer. Apparently , it is not possible to get the owner by some javascript/rpc call, apparently, you have to scan all the transactions to find out who the owner is.
    – Nulik
    Mar 12, 2018 at 1:48
  • @ThomasJayRush When using Block Explorer APIs, it is usually correct, as those will list the creation transaction as the first transaction involving the address, even though it's neither the sender nor the receiver.
    – CherryDT
    Aug 22, 2022 at 10:58

5 Answers 5

5

If possible, save the users, transactions and contracts as you send them. This way you don't have to look for them later.

If that's not an option, the long route is to find all the transactions related to the contract address. The first incoming one should be the contract creation transaction, the sender of which is the creator.

1
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – q9f
    Mar 9, 2017 at 21:46
5

If you understand how etherscan works you'll be able to do what you are asking.

See : How does Etherscan work?

What etherscan do is reverse of what you are trying to. ie you are trying to get the creator of a contract from an address. Etherscan index the entire blockchain and create relationships between blocks, transactions and accounts.

Etherscan see a block and index all the transactions first, then associate the creation of contracts with the accounts that sent the transactions.


I presuming you are asking for a native geth/web3/etc method that would give you a contract creators address. If so I am not aware of any such method.

4

If you use Etherscan or some other third party blockchain scraper, then chances are the first transaction returned by their API will be the contract creation transaction. You'll be able to tell because the first transaction in the list will have been sent to address 0x0. I'm pretty sure this is how Etherscan works. I'm not sure about other blockchain scrapers. It will be obvious because the transaction will have a to value of 0x0 and the bytecode in the input data field.

If you're looking for a solution that reads directly from the blockchain (i.e. a locally running node), then the only way to find a contract's creation transaction (if you don't know the deploying account) is to scan the chain looking for the address of the contract you're interested in. Look in the transaction receipt's contractAddress data field. Any particular contract address will only ever appear once in a single transaction's receipt. And that transaction will be the transaction in which the contract was deployed.

If you’re lucky you will have written a “contractCreated” event in your deploying smart contract. You won’t be able to get the address during the transaction, but the event will tell you which transaction it is.

1

Otherwise more specifically you can use an attribute in your contract that will store the creator. This attribute can be read by any contract or dapp.

Example:

pragma solidity ^0.4.8;
contract myContract  {

    address public creator;

    function myContract() {
        creator = msg.sender;
    }
}
3
  • The issue with this is someone could make a similar contract to mine except it defines creator as my address instead of msg.sender. This would look identical to a contract made by me wouldnt it?
    – Joe
    Mar 8, 2017 at 13:21
  • In that case, instead of checking the creator. You could simply try to share a secret between the factory and the contract. For a given contract, if the factory doesn't know the secret (in a map for example), it can't be trusted. Mar 8, 2017 at 13:34
  • Im not entirely sure what type of secret you mean. I considered using signing but contracts dont have private addresses
    – Joe
    Mar 8, 2017 at 13:39
0

You can binary search on all blocks for existence of w3.eth.get_code. Given that at the time of this answer the ethereum chain is on block 15581647, it'll take about log2(15581647) = 24 calls to chain node to get to the creation transaction for that contract. The from field of that transaction will give you the creator of that contract.

3
  • Hi could you elaborate on your algorithm to find a needle in a haystack of 15581647 blocks with just 24 calls? The way your answer stands it’s not very actionable for most, including me. Thanks!
    – blitter
    Sep 24, 2022 at 18:40
  • First please make sure you understand how binary search works. Let's say there were only 512 blocks and the contract was created at block 183. If you call w3.eth.get_code on block < 183 it'd return no code but for blocks >=183 it'd return the code. We don't know that our answer is 183 as yet so we binary search for it. We call get_code for block (0+512)/2=256 and we find that it returns the code, so it was created in 0 to 256. Then we do for (0+256)/2=128 and it'd not return code. Then for (128+256)/2=192 and so on.
    – Orwell
    Sep 27, 2022 at 7:39
  • This answer might help with implementation.
    – Orwell
    Sep 27, 2022 at 7:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.