# Babypie's Architecture

<figure><img src="/files/qmanDP1cdvubn2fY26FL" alt=""><figcaption></figcaption></figure>

**1. Register Wallet:** User sends the following values to the Babypie Manager:

* User’s BTC address
* User’s EVM address
* Signature generated using the Bitcoin wallet by passing the EVM address as the message.

<figure><img src="/files/XDMypetoIQpsDypOsgVb" alt=""><figcaption></figcaption></figure>

**2. Babypie Manager Action:** The Babypie Manager calls the Chainlink Functions Consumer contract, passing the three values it received from the user.

* Babypie Manager: One of Babypie’s smart contracts.
* Functions Consumer: A smart contract that can send Functions requests to the Chainlink Oracle Network, where the oracle network returns the results of decentralized computation.

**3. Chainlink Functions Consumer Contract Action:** The Chainlink Functions Consumer contract sends a request to the Chainlink DON to run the script to verify the user's signature, using the EVM address as the message string.

* [DON - Decentralized Oracle Network](https://docs.chain.link/chainlink-functions/resources/architecture)

**4. Verification Result:** The DON returns the result of the verification to the Chainlink Functions Consumer contract by calling it with the result (this process takes around 30 seconds).<br>

**5. Update User Mapping:** The Chainlink Functions Consumer contract calls the Babypie Manager contract to update the user's BTC to EVM mapping if the signature is valid.

### Now, the user can transfer native BTC to Babypie’s MPC wallet (This step can even be done by user before mapping their BTC->EVM address)<br>

**6. BTC Transfer:** The user calls the Babypie Manager with the transaction hash of the BTC transfer to Babypie’s MPC wallet and the BTC address used for the transfer.

<figure><img src="/files/SbAFa1KpC0P1zX7dsxLj" alt=""><figcaption></figcaption></figure>

**7. Requests to initiate mBTC mint for BTC transfer:** User calls babypie manager to initiate verification of user's BTC transfer in txn and mint mBTC to user's mapped EVM address.

**8. Babypie Manager Action:** The Babypie Manager calls another Chainlink Functions Consumer contract with the transaction hash and the user’s BTC chain address.

**9. BTC Amount Retrieval:** The Chainlink Functions Consumer contract sends a request to the Chainlink DON to run a script that will get the amount of BTC transferred to the Babypie MPC wallet in the transaction.

**10. Amount Confirmation:** The Chainlink Functions Consumer contract receives the result (amount of BTC transferred) of the script from the Chainlink DON.

**11. Validation and Processing:** The Chainlink Functions Consumer contract checks if the amount is greater than 0. If yes, it calls the Babypie Manager with the result.

**12. Mark txn paid:** The Babypie Manager will mark the txn as paid and call the mint function of the mBTC contract with value equal to BTC transferred by user.

**13. mBTC mint:** mBTC token will be minted to the user.

<figure><img src="/files/3V60KQe21YMwRe6y0JNl" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.babypiexyz.io/babypies-architecture.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
