# CCTP

## CCTP Transaction

The Circle Cross-Chain Transfer Protocol (CCTP) is a solution designed by Circle to facilitate simple and secure transfers of USDC across different blockchain networks. This eliminates the need for multiple versions of USDC, since the protocol operates as a decentralized bridge, utilizing a **burn-and-mint process.**

<figure><img src="/files/dSLEpPz0gXe7Z4PHSFDQ" alt=""><figcaption><p>CCTP - Burning and Minting</p></figcaption></figure>

When a user initiates a transfer, USDC is burned on the source chain and an equivalent amount is minted on the destination chain, maintaining a consistent total supply. CCTP ensures secure and efficient transfers through a decentralized validation mechanism, optimizing transaction speeds and reducing costs.

## CCTP in Mach

In the case of a CCTP transaction through Mach, the process is delegated to the market maker, adopting an optimistic approach by fronting the capital for users. This is secured through CCTP's mint and burn functionality. As a result, rather than waiting over 20 minutes for a large-scale transaction to be processed, the transaction can be processed immediately, provided there is sufficient liquidity.

Furthermore, Mach incorporates certain novel CCTP routing solution, that enables the system to settle transactions at a faster speed than most competitors.

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

{% embed url="<https://developers.circle.com/stablecoins/docs/cctp-getting-started>" %}

## Recieving CCTP Transaction on Server

### To successfully receive a CCTP transaction on the server, follow these steps:

**Step 1: Burn USDC on the Source Chain**

Before submitting a POST request to receive CCTP on the server, you must first burn USDC on the source chain (src\_chain). This burn transaction is referred to internally as the `burn_tx`.

**Important:**

* Ensure that the public destination address is \[**TREVOR NEEDS TO FILL THIS**].

**Step 2: Send Transaction to Circle CCTP Token Messenger Contract**

Send a transaction on the src\_chain to the Circle CCTP Token Messenger Contract by calling the `depositForBurn` function. Use our wallet's public address as the destination address.

The `depositForBurn` function facilitates these cross-chain token transactions, ensuring that the specified amount of tokens is burned. The transaction is directed to the appropriate destination domain, and the minted tokens are sent to the correct recipient address. This method helps in reducing transaction speeds and costs while retaining optimal security by managing the funds through smart contracts.

```
// Function to call depositForBurn on the tokenMessenger contract
function CCTP_Trade(
    uint256 amount,
    uint32 destinationDomain,
    bytes32 mintRecipient,
    address sell_token
) 
    external 
    payable 
    returns (uint64 nonce)
{
    // Send in
    transferFrom(sell_token, msg.sender, amount);
    
    // Calling depositForBurn function of the tokenMessenger contract
    nonce = tokenMessenger.depositForBurn(apply_fee(amount), destinationDomain, mintRecipient, sell_token);
    
    transfer(sell_token, owner(), owner_fee(amount));
    
    emit CCTPTrade(msg.sender, amount, sell_token, destinationDomain);
    
    payable(owner()).transfer(msg.value);
}
```

**Important:**

* Our wallet’s public address is: \[**I NEED TO ASK TREVOR FOR THIS**].

**Step 3: Obtain the Message Hex**

After making the burn transaction, you need to obtain its message hex. There are two ways to do this:

**Manually:**

```python
pythonCopy codetx_receipt = await asyncio.to_thread(web3.eth.wait_for_transaction_receipt, burn_tx)
log = arb_token_messenger_contract.events.MessageSent().process_receipt(tx_receipt)[0]
message_bytes = log.args.message
message_hex = message_bytes.hex()
```

**Using the Endpoint:**

You can call the `/get_message_hex_from_burn_tx` endpoint by providing the src\_chain and the burn transaction hash (`burn_tx`). More details can be found [here](https://cache-half-full-staging.fly.dev/docs#/default/get_message_hex_from_burn_tx).

**Step 4: Make a POST Request to Receive CCTP**

Once you have the `message_hex`, make a POST request to the `/receive_cctp` endpoint. Provide the `message_hex` from the previous step and the destination chain name (`dst_chain_name`). Refer to the endpoint documentation [here](https://cache-half-full-staging.fly.dev/docs#/default/receive_cctp).<br>

[Find a more direct example here.](https://arbiscan.io/address/0x19330d10D9Cc8751218eaf51E8885D058642E08A#code)

<figure><img src="https://lh7-us.googleusercontent.com/5HubZofOEHVxfAWg9Yu1Z0oaUfk02edUfo3V-tvYyNeZc2GQJjMemn-srfeT1PqSqI40b9Wt0CTqYrokxRnvr2ak34h7YLc66p-uA-RjkYnUl1IC8FvlqNgQzXdmFsP-CpDChgsAfjaBdYLEnIUy_bM" alt=""><figcaption></figcaption></figure>

{% embed url="<https://developers.circle.com/stablecoins/docs/evm-smart-contracts>" %}


---

# 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://mach-4.gitbook.io/mach/protocol/cctp.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.
