# CoreWriter Integration Guide

This guide outlines the integration steps for using the CoreWriter feature. It builds upon the standard bridge flow, adding CoreWriter-specific parameters and requirements. For the base bridge integration reference, please refer to the [Bridge Integration Guide](https://www.notion.so/Bridge-Integration-Guide-2692e5205de5807dbc1fd2dc9f242bb7?pvs=21) or the [Swagger documentation](https://petstore.swagger.io/?url=https://bridge-ag-api.hyperflow.fun/v1/swagger).

## Steps to Integrate

### Step 1. Get Your Partner Code

Before initiating any CoreWriter bridge transactions, **partners should obtain a partner code.** To get your partner code: Contact the HyperFlow team to receive your unique partner code (e.g., `lifi`). Contact us:

* Discord: <https://discord.gg/GGDmD4K9CK>
* Telegram: <https://t.me/hyperflow_fun>
* X: <https://x.com/HyperFlow_fun>

### Step 2. Generate a Quote

This step is to generate a quote \*\*\*\*using `/v1/quote`. It is similar to step 1 on [Bridge Integration Guide](https://hyperflow-fun-1.gitbook.io/hyperflow/developer/bridge-integration-guide), but with additional constraints and parameters specific to CoreWriter.

#### **Required parameters**

All parameters from the base `/v1/quote` apply. However, note the following rules:

* `fromChain`: Must always be **“hyperevm”**.
* `toChain`: Must always be **“hypercore”** or **“hyperevm”**.
  * If `toChain = "hypercore"` , then `toToken` must be a token id, which is retrieved from the [**Hyperliquid Spot Metadata API**](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/spot#retrieve-spot-metadata) using the following request:

    ```jsx
    curl --location '<https://api.hyperliquid.xyz/info>' \\
    --header 'Content-Type: application/json' \\
    --data '{
        "type": "spotMeta"
    }'
    ```
  * If `toChain = "hyperevm"`, then the fund amount must be at least equivalent to 100 USD (based on the source token value), to ensure quotes are returned.
* `source`: Should include your partner code (obtained from above step).

Example 1: Bridge 10 **HYPE** from **hyperevm → hypercore**

```jsx
const params = {
  fromChain: "hyperevm",
  fromToken: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
  toChain: "hypercore",
  toToken: "0x0d01dc56dcaaca66ad901c959b4011ec",
  amount: "10000000000000000000",
  protocols: "kyberswap,hyperflow,wrapnative,hypercorespot,hypercore,layerzero,hyperunit,gaszip,relay,mayan",
  sender: "0xf89d7b9c864f589bbF53a82105107622B35EaA40",
  receiver: "0xf89d7b9c864f589bbF53a82105107622B35EaA40",
  slippage: "100",
  source: "lifi"
};
```

Example 2: Bridge 10 **HYPE** to **USDT0** on **hyperevm** (similar to a swap action).

```jsx
const params = {
  fromChain: "hyperevm",
  fromToken: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
  toChain: "hyperevm",
  toToken: "0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb",
  amount: "10000000000000000000",
  protocols: "kyberswap,hyperflow,wrapnative,hypercorespot,hypercore,layerzero,hyperunit,gaszip,relay,mayan",
  sender: "0xf89d7b9c864f589bbF53a82105107622B35EaA40",
  receiver: "0xf89d7b9c864f589bbF53a82105107622B35EaA40",
  slippage: "100",
  source: "lifi"
};
```

**Note**: The response includes a `requestId` , which is required for the next step. The `requestId` is expired after **30 seconds**.

### Step 3: Assemble the Transaction

This step is identical to step 2 on [Bridge Integration Guide](https://hyperflow-fun-1.gitbook.io/hyperflow/developer/bridge-integration-guide). Use the `requestId` from above step to request encoded transaction data from `/v1/encode`.

```jsx
const txData = await fetch(`${api}/encode`, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    requestId: quote.requestId,
    quoteIdx: selectedQuoteIndex,
  }),
}).then((r) => r.json());
```

### Step 4: Submit the Transaction

Once you have the encoded transaction, you can submit it on-chain using any EOA wallet or contract execution method.

```jsx
const txRes = await wallet.sendTransaction(transaction);
console.log("tx_hash:", txRes.hash);
const receipt = await txRes.wait();
console.log("mined_block:", receipt.blockNumber);
```

### Step 5: Check Bridge Status

After submission, track the bridge’s progress using `/v1/hyperbridge/orders?src_tx=<tx_hash>`.

```jsx
const status = await fetch(`${api}/hyperbridge/orders?src_tx=${tx_hash}`).then((r) => r.json());
if (status.orders.length > 0) console.log("tx:", status.orders[0]);
```

**Understanding the `state` field in the response:**

* `done` - The user receives the entire fund in the form of the `dstToken` and on the `dstChain`.
* `refunded` - The user receives up to two tokens, ensuring the full fund value is received. The refund is processed and received on **Hyperliquid**, regardless of `dstChain` is `hypercore` or `hyperevm`.
* `pending` - The bridge transaction is still in progress.
* `failed` - The bridge transaction has failed, the user can wait for a retry or contact HyperFlow Team for assistance.

### Need Help?

* Refer to the [Bridge Integration Guide](https://hyperflow-fun-1.gitbook.io/hyperflow/developer/bridge-integration-guide) for detailed on basic bridge steps.
* For questions or partnership setup, contact the **HyperFlow team**.
* Join the developer community on **Discord** for live support.
