pub async fn get_contract_info_for_verification(
        &mut self,
        address: Address,
    ) -> DalResult<Option<DeployedContractData>> {
        let address_h256 = address_to_h256(&address);
        sqlx::query!(
            r#"
            SELECT
                factory_deps.bytecode_hash,
                factory_deps.bytecode,
                transactions.data -> 'calldata' AS "calldata?",
                transactions.contract_address AS "contract_address?"
            FROM
                (
                    SELECT
                        miniblock_number,
                        tx_hash,
                        topic3
                    FROM
                        events
                    WHERE
                        address = $1
                        AND topic1 = $2
                        AND topic4 = $3
                    ORDER BY miniblock_number DESC, event_index_in_block DESC
                    LIMIT
                        1
                ) deploy_event
            JOIN factory_deps ON factory_deps.bytecode_hash = deploy_event.topic3
            LEFT JOIN transactions ON transactions.hash = deploy_event.tx_hash
            WHERE
                deploy_event.miniblock_number <= (
                    SELECT
                        MAX(number)
                    FROM
                        miniblocks
                )
            "#,
            CONTRACT_DEPLOYER_ADDRESS.as_bytes(),
            VmEvent::DEPLOY_EVENT_SIGNATURE.as_bytes(),
            address_h256.as_bytes(),
        )
        .try_map(|row| {
            Ok(DeployedContractData {
                bytecode_hash: H256::from_slice(&row.bytecode_hash),
                bytecode: row.bytecode,
                contract_address: row.contract_address.as_deref().map(Address::from_slice),
                calldata: row
                    .calldata
                    .map(|calldata| {
                        serde_json::from_value::<web3::Bytes>(calldata)
                            .decode_column("calldata")
                            .map(|bytes| bytes.0)
                    })
                    .transpose()?,
            })
        })
        .instrument("get_contract_info_for_verification")
        .with_arg("address", &address)
        .fetch_optional(self.storage)
        .await
    }
Returns bytecode and calldata from the contract and the transaction that created it.
core/lib/dal/src/contract_verification_dal.rs