# SDK

## Install

#### install with npm

{% code overflow="wrap" %}

```bash
npm install owlto-sdk
```

{% endcode %}

#### install with yarn

```bash
yarn add owlto-sdk
```

## Usage

{% embed url="<https://github.com/owlto-finance/owlto-sdk/blob/main/README.md>" %}

For example, to bridge USDC from Base to Scroll

```typescript
import * as owlto from "owlto-sdk";

const options: owlto.BridgeOptions = {}
let bridge = new owlto.Bridge(options);

const result = await bridge.getBuildTx(
    "USDC", //token name
    "BaseMainnet", //from chain name
    "ScrollMainnet",// to chain name
    "1", // value
    "0xa5E56D455BF247C475D752721Ba35A0c85Df81Dc", // from address
    "0xa5E56D455BF247C475D752721Ba35A0c85Df81Dc", // to address
);

//initialize your wallet
//...

if (result.txs.approveBody) {
    const tx = await wallet.sendTransaction(result.txs.approveBody as ethers.TransactionRequest);
    await tx.wait(); 
}

const tx = await wallet.sendTransaction(result.txs.transferBody as ethers.TransactionRequest);
await tx.wait(); 

const receipt = await bridge.waitReceipt(tx.hash)
console.log(receipt)
```

For more details, check the example/bridge\_usdc folder.

#### Bridge options

**1.chainNameMapping (Map\<string, string> | optional)**

Map your the chain names from your protocol with Owlto.

For example, if the chain name of Base Mainnet on your protocol is "Base", you can set `chainNameMapping["Base"] = "BaseMainnet"`.

Then you can run functions with chain name as "Base" in order to proceed with a bridge.

#### Get build tx

```typescript
const result = await bridge.getBuildTx(
    "USDC", //token name
    "BaseMainnet", //from chain name
    "ScrollMainnet",// to chain name
    "1", // value
    "0xa5E56D455BF247C475D752721Ba35A0c85Df81Dc", // from address
    "0xa5E56D455BF247C475D752721Ba35A0c85Df81Dc", // to address
);

//result:
{
 ...
  networkType: 1; //
  txs: any; //actual transactions need to be sent to from chain, see the following details
}
```

The txs contains the transactions user should send to `from chain` when bridging.

**1.Evm**

* **txs.approveBody**

  The approve transaction, if any, should be sent first.
* **txs.transferBody**

  The actual transfer transaction.

**2.Starknet**

Coming Soon

**3.Solana**

Coming Soon

#### Get receipt

1. `bridge.waitReceipt(fromChainHash: string)`
2. `bridge.getReceipt(fromChainHash: string)`

`fromChainHash` is the hash value of the transfer transaction.

`waitReceipt` refers to waiting for the bridge process to complete.

If the bridge process is not completed within 1 minute (usually due to not finding the hash value or failure), error message will be displayed.

`getReceipt` refers to get the status of a bridge process.

If `fromChainHash` is not found, bridge is in progress or failed, error message will be displayed.

#### Get pair info

1. `bridge.getPairInfo(tokenName: string, fromChainName: string, toChainName: string)`
2. `bridge.getAllPairInfos()`

A pair consists of three components: `token name`, `from chain name`, `to chain name`.

You can only bridge supported pairs

#### HTTP API Documentation

Please visit: <https://owlto.finance/bridge_api/v1/swagger/index.html> .


---

# 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.owlto.finance/integration-guides/sdk.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.
