# Can you interact with a public-state application with private addresses

**URL:** <https://forum.aztec.network/t/can-you-interact-with-a-public-state-application-with-private-addresses/2548>\
**Category:** General\
**Created:** [November 16, 2023, 8:49pm UTC](https://forum.aztec.network/t/can-you-interact-with-a-public-state-application-with-private-addresses/2548 "2023-11-16T20:49:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fouda](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.aztec.network/fouda/32/849_2.png) [@Fouda](https://forum.aztec.network/u/Fouda)\
**Post date:** [November 16, 2023, 8:49pm UTC](https://forum.aztec.network/t/can-you-interact-with-a-public-state-application-with-private-addresses/2548/1 "2023-11-16T20:49:55Z")

</div>

I am trying to understand how private transactions can work with applications within the Aztec protocol.

For example, if you have an AMM implemented on the L2 that have an ETH-USDC pool, can a user execute a private swap transaction with this pool?

Here is how I imagine the transaction execution would work. The user sends the ETH to be swapped to the AMM as a private TX. The AMM then exposes the ETH mount to execute the swap. The resulting USDC will be sent as a private balance to the user’s address.

Is this flow possible?

---

<div class="post-metadata">

**Author:** ![Jan](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.aztec.network/jan/32/2727_2.png) [@Jan](https://forum.aztec.network/u/Jan)\
**Post date:** [November 17, 2023, 4:22pm UTC](https://forum.aztec.network/t/can-you-interact-with-a-public-state-application-with-private-addresses/2548/2 "2023-11-17T16:22:26Z")

</div>

Hello @Fouda, yes the flow you described is possible and quite easy to do. You would use the unshielding and shielding flow for that. Here is how it would work:

1. you choose a random secret,
2. you compute a hash of that secret (secret\_hash)
3. you call a private function swap(token\_in, token\_out, secret\_hash, amount)
4. This swap function spends/nullifies a note (or multiple notes) containing your private eth balance,
5. then a pubic function would get called by the private function. The function would be something like swap\_public(token\_in, token\_out, secret\_hash, amount). This function would do the actual swap on AMM and then it would shield the resulting funds (USDC) by creating a TransparentNote with the secret hash. See [this function](https://github.com/AztecProtocol/aztec-packages/blob/dd9dd84e9cfc93f8605f28aa25fa36b0004052cb/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr#L215) for a real-world example of shielding.
6. User would call redeem\_shield(secret) function, the function would check whether hash(secret) matches secret hash and if yes, it would create a new note representing the usdc balance. Example is [here](https://github.com/AztecProtocol/aztec-packages/blob/dd9dd84e9cfc93f8605f28aa25fa36b0004052cb/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr#L276).

Let me know if something is not clear. Feel free to also check the e2e\_token.test.ts in aztec-packages repository to see how the flow is triggered from typescript.

---

<div class="post-metadata">

**Author:** ![Fouda](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.aztec.network/fouda/32/849_2.png) [@Fouda](https://forum.aztec.network/u/Fouda)\
**Post date:** [November 17, 2023, 7:09pm UTC](https://forum.aztec.network/t/can-you-interact-with-a-public-state-application-with-private-addresses/2548/3 "2023-11-17T19:09:03Z")

</div>

Thanks @Jan for the detailed answer and even mentioning the functions.
