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.