How can I get the address of the creator of a contract using web3j? Is it possible to get the first transaction of a contract and assume that the "from" field is the contract creator? If so, how can I get the first transaction?
Is it possible to get the first transaction of a contract and assume that the "from" field is the contract creator
This assumption is wrong. Indeed a contract is created with a contract creation (i.e. either with a transaction or with an internal transaction).
The address of the contract is obtained by taking the last 160bits of the
keccak256(rlp(creator_address, nonce of the creator)).
I think that one possibility could be to iterate over the transactions and use the equivalent of eth_getTransactionReceipt and check if the obtained object contains the
contractAddress field and check if the
contractAddress correspond to the searched one. Then you have to check which address created the transaction. So you can (potentially) detect the address of the creator (I think that you should know in which block range you have to search). The problem is that it works only with contract creation caused by transaction and presumably not with internal transaction, i.e., when the contract was created during the execution of a message call/contract creation.
If the contract stores the owner (e.g., it contains in the constructor something like
owner=msg.sender and owner is a public variable) you could read the address of the owner directly
APPROACH 3 - Without web3j
Use etherscan to check the creator of the contract
Maybe there are plenty of other possibilities, that I did not figure out..