bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 38쪽 중 2쪽
M chains (e.g., evm-1). These return a `404` on
non-EVM chains.
# Introduction
Source: https://docs.initia.xyz/api-reference/router-api/introduction
Overview of the Initia Router API for cross-chain asset transfers.
The Router API supports cross-chain transfers from Initia Stack-based chains to
external networks, automatically determining the optimal route across supported
networks, chains, and DEXes.
## Base URL
The Router API is available at the following base URL:
* Mainnet: `https://router-api.initia.xyz`
* Testnet: `https://router-api.initiation-2.initia.xyz`
## Features
* **Asset Queries** — Query supported fungible assets and chains across Initia
and external networks
* **Balance Queries** — Fetch token balances and USD values across multiple
chains
* **Route Computation** — Find optimal transfer paths between any supported
source and destination
* **Transaction Generation** — Get signable transaction messages for computed
routes
* **Transaction Tracking** — Monitor cross-chain transfer progress
* **NFT Transfers** — Bridge NFTs across Initia L1 and L2 chains via ICS-721
* **RPC Proxy** — Forward a limited set of JSON-RPC requests to supported Cosmos
chains
# Usage
Source: https://docs.initia.xyz/api-reference/router-api/usage
How to bridge tokens and track transfers using the Router API.
The Router API handles route computation and transaction generation, but does
not broadcast transactions. The application is responsible for signing and
submitting the transaction to the chain. This page walks through the full flow.
## Flow Overview
```mermaid theme={null}
sequenceDiagram
participant App
participant Router API
participant Chain RPC
App->>Router API: 1. Compute Route
Router API-->>App: Route + operations
App->>Router API: 2. Generate Transaction
Router API-->>App: Signable tx messages
App->>Chain RPC: 3. Sign & broadcast
Chain RPC-->>App: tx_hash
App->>Router API: 4. Track Transaction (tx_hash)
Router API-->>App: Registered
loop Until terminal state
App->>Router API: 5. Get Transaction Status
Router API-->>App: Status + transfer sequence
end
```
## Bridging Tokens
Bridging tokens between chains is a two-step process using the Routing
endpoints.
<Steps>
<Step title="Compute a route">
Call **Compute Route** (`POST /v2/fungible/route`) with the source and destination assets and the amount to transfer. The API evaluates available pathways (IBC, LayerZero, Optimistic bridges, etc.) and returns the optimal route, including the expected output amount and an `operations` array for each hop.
```bash theme={null}
curl -X POST https://router-api.initia.xyz/v2/fungible/route \
-H "Content-Type: application/json" \
-d '{
"amount_in": "1000000",
"source_asset_chain_id": "interwoven-1",
"source_asset_denom": "uinit",
"dest_asset_chain_id": "8453",
"dest_asset_denom": "0x..."
}'
```
</Step>
<Step title="Generate transaction messages">
Pass the route details to **Generate Transaction** (`POST /v2/fungible/msgs`) along with the relevant addresses and slippage tolerance. The API returns signable transaction messages for the source chain.
If the route response included `required_op_hook: true`, first call **Get OP Hook** (`POST /op-hook`) with the source and destination addresses and assets to obtain the hook payload. Then sign the hook and include it in the `signed_op_hook` field of the Generate Transaction request.
```bash theme={null}
curl -X POST https://router-api.initia.xyz/v2/fungible/msgs \
-H "Content-Type: application/json" \
-d '{
"amount_in": "1000000",
"amount_out": "999000",
"source_asset_chain_id": "interwoven-1",
"source_asset_denom": "uinit",
"dest_asset_chain_id": "8453",
"dest_asset_denom": "0x...",
"address_list": ["init1abc...", "0xdef..."],
"operations": [],
"slippage_tolerance_percent": "1"
}'
```
</Step>
<Step title="Sign and broadcast">
Sign the returned transaction messages with a wallet or SDK, then broadcast to the source chain's RPC endpoint. This step happens outside the Router API.
</Step>
</Steps>
## Tracking Transfers
Because the transaction is signed and broadcast outside the Router API's scope,
the API has no knowledge of the transaction until the application explicitly
provides the transaction hash. The transaction must be registered before its
cross-chain progress can be monitored.
<Steps>
<Step title="Register the transaction">
After broadcasting, call **Track Transaction** (`POST /v2/tx/track`) once with the transaction hash and the chain ID where it was submitted. This registers the transaction so the tracking service can watch for relay events and bridge confirmations.
```bash theme={null}
curl -X POST https://router-api.initia.xyz/v2/tx/track \
-H "Content-Type: application/json" \
-d '{
"tx_hash": "ABCDEF1234567890...",
"chain_id": "interwoven-1"
}'
```
</Step>
<Step title="Poll for status">
Call **Get Transaction Status** (`GET /v2/tx/status`) repeatedly to check the transfer progress. The response includes the overall status and the state of each hop in the transfer sequence.
```bash theme={null}
curl "https://router-api.initia.xyz/v2/tx/status?tx_hash=ABCDEF1234567890...&chain_id=interwoven-1"
```
Keep polling until the status reaches a terminal state such as `STATE_COMPLETED` or `STATE_FAILED`.
</Step>
</Steps>
## Endpoint Reference
| Step | Endpoint | Purpose |
| ---- | ------------------------- | ------------------------------------------ |
| 1 | `POST /v2/fungible/route` | Find the optimal route |
| 1b | `POST /op-hook` | Get OP hook data (when `required_op_hook`) |
| 2 | `POST /v2/fungible/msgs` | Get signable transaction messages |
| 3 | *(wallet/SDK)* | Sign and broadcast to the chain |
| 4 | `POST /v2/tx/track` | Register the tx hash for tracking |
| 5 | `GET /v2/tx/status` | Poll until transfer completes |
# Compute Route
Source: https://docs.initia.xyz/api-reference/routing/compute-route
/api-reference/router-api/openapi.yaml post /v2/fungible/route
This is the first step when bridging tokens between chains. Call this endpoint with your source and destination assets to find the optimal transfer route. The response includes the expected output amount, USD value estimates, and an ordered list of operations.
After receiving a route, pass the full response (including `operations`) to the Generate Transaction endpoint (`POST /v2/fungible/msgs`) to get signable transaction messages you can broadcast.
If the route involves an IBC transfer between the Initia L1 chain and an external Cosmos chain, the endpoint also checks that the transfer fits within the current IBC rate-limit capacity. When the requested amount exceeds the remaining send or receive capacity, the request is rejected with a `400` error whose message reports the remaining capacity in human-readable units.
# Generate Transaction
Source: https://docs.initia.xyz/api-reference/routing/generate-transaction
/api-reference/router-api/openapi.yaml post /v2/fungible/msgs
This is the second step when bridging tokens. After computing a route with Compute Route (`POST /v2/fungible/route`), pass the route details and your addresses to this endpoint. It returns signable transaction messages that you can broadcast to the source chain.
The typical flow is: **Compute Route** → **Generate Transaction** → sign and broadcast → **Track Transaction**.
# Get OP hook
Source: https://docs.initia.xyz/api-reference/routing/get-op-hook
/api-reference/router-api/openapi.yaml post /op-hook
Generates OP hook data required for certain cross-chain routes that involve Optimistic bridge withdrawals with ERC-20 token conversion. When the Compute Route response includes `required_op_hook: true`, you must call this endpoint to obtain the hook payload before generating transaction messages.
Pass the returned hook data to the Generate Transaction endpoint (`POST /v2/fungible/msgs`) in the `signed_op_hook` field after signing it.
# Cosmos RPC Proxy
Source: https://docs.initia.xyz/api-reference/rpc/cosmos-rpc-proxy
/api-reference/router-api/openapi.yaml post /api/rpc/{chainId}
JSON-RPC 2.0 proxy to the Cosmos RPC of a supported Cosmos chain. The request and response follow the standard [JSON-RPC 2.0 specification](https://www.jsonrpc.org/specification).
Only a limited set of RPC methods is supported:
- `status` — fetch the node status. `params` must be `{}`.
- `abci_query` — query application state. `params` must include `data` (string), `path` (string), and `prove` (boolean). Allowed `path` values:
- `/cosmos.auth.v1beta1.Query/Account`
- `/cosmos.bank.v1beta1.Query/AllBalances`
- `/cosmos.tx.v1beta1.Service/Simulate`
- `broadcast_tx_sync` — broadcast a signed transaction. `params` must contain a single `tx` field (string).
- `tx_search` — search for transactions. `params` must include `page` (string, only `"1"` is allowed) and `query` (string, must match `tx.hash='<64-hex>'`).
Any other method or unsupported parameter shape returns a `400` error.
# Get Transaction Status
Source: https://docs.initia.xyz/api-reference/tracking-transactions/get-transaction-status
/api-reference/router-api/openapi.yaml get /v2/tx/status
Polls the current status of a transaction that was previously registered with Track Transaction (`POST /v2/tx/track`). Returns the overall status and the state of each hop in the transfer sequence.
Call this endpoint repeatedly until the status reaches a terminal state (e.g. `STATE_COMPLETED` or `STATE_FAILED`). This is useful for showing transfer progress in your UI.
# Track Transaction
Source: https://docs.initia.xyz/api-reference/tracking-transactions/track-transaction
/api-reference/router-api/openapi.yaml post /v2/tx/track
Registers a transaction for cross-chain tracking. Call this once with the transaction hash and chain ID immediately after broadcasting. This is required before you can poll the transaction status.
After calling this endpoint, use Get Transaction Status (`GET /v2/tx/status`) to poll for progress updates.
# Get transaction by hash
Source: https://docs.initia.xyz/api-reference/transactions/get-transaction-by-hash
/api-reference/rollup-indexer/openapi.yaml get /indexer/tx/v1/txs/{tx_hash}
Returns a specific transaction by its hash.
# Get transactions
Source: https://docs.initia.xyz/api-reference/transactions/get-transactions
/api-reference/rollup-indexer/openapi.yaml get /indexer/tx/v1/txs
Returns a paginated list of transactions. You can optionally filter by message type.
# Get transactions by account
Source: https://docs.initia.xyz/api-reference/transactions/get-transactions-by-account
/api-reference/rollup-indexer/openapi.yaml get /indexer/tx/v1/txs/by_account/{account}
Returns transactions associated with a specific account address.
# Get transactions by height
Source: https://docs.initia.xyz/api-reference/transactions/get-transactions-by-height
/api-reference/rollup-indexer/openapi.yaml get /indexer/tx/v1/txs/by_height/{height}
Returns all transactions at a given block height.
# Exchange Integration
Source: https://docs.initia.xyz/developers/developer-guides/guides/exchange-integration
This guide provides instructions for exchanges on how to integrate with Initia,
from running a node to handling transactions and monitoring network activities.
## Network Details
You can find the details of Initia's network, including the chain endpoints,
nodes, and peer information, below.
* [Initia L1 Networks](/resources/developer/initia-l1)
## Running a Node
For more information on running a node, please refer to
* [Running an Initia Node](/nodes-and-rollups/running-nodes/running-l1-nodes/l1-nodes-initiad)
## Creating and Managing Accounts
* [Creating an Account](/developers/developer-guides/tools/sdks/initia-js/accounts)
## Sending Transactions
### Transferring Tokens
* [Sending Transactions](/developers/developer-guides/tools/sdks/initia-js/transactions/sending-transactions)
### Signing Transactions Offline
In cases where network security is crucial, signing transactions offline ensures
safe transaction handling.
* [Signing Transactions](/developers/developer-guides/tools/sdks/initia-js/transactions/signing-transactions)
### Handle Transaction Errors
Learn how to handle transaction errors to ensure that your transactions are
executed properly.
* [Handling Errors](/developers/developer-guides/tools/sdks/initia-js/transactions/handling-errors)
## Monitoring Transactions
Initia provides various tools to monitor transaction activities, including event
indexing and querying network data.
To keep track of transactions and blockchain events, you can use a simple
indexer example:
* [Simple Indexer](https://github.com/initia-labs/simple-indexer)
For additional data like account balances and block details, you can use
InitiaJS:
* [Querying Data](/developers/developer-guides/tools/sdks/initia-js/querying-data)
Additionally, you can manually monitor transactions with the following tools:
* [InitiaScan](https://scan.testnet.initia.xyz/initiation-2)
* [REST Swagger](https://rest.testnet.initia.xyz/swagger/#/Service/GetTx)
# Interacting with InitiaDEX
Source: https://docs.initia.xyz/developers/developer-guides/integrating-initia-apps/initiadex
## Creating New Pools
InitiaDEX allows anyone to create a liquidity pool.
```move theme={null}
public entry fun create_pair_script(
creator: &signer,
name: String,
symbol: String,
swap_fee_rate: Decimal128,
coin_a_weight: Decimal128,
coin_b_weight: Decimal128,
coin_a_metadata: Object<Metadata>,
coin_b_metadata: Object<Metadata>,
coin_a_amount: u64,
coin_b_amount: u64,
)
```
| Parameter | Description |
| --------------------------------------- | ------------------------------------------------------- |
| `name` | Name of the trading pair and the corresponding LP Token |
| `symbol` | Symbol for the LP Token |
| `swap_fee_rate` | Fee rate applied to swaps |
| `coin_a_weight` and `coin_b_weight` | Balancer weights for the respective coins |
| `coin_a_metadata` and `coin_b_metadata` | Metadata for each coin in the pair |
| `coin_a_amount` and `coin_b_amount` | Initial amounts for each coin |
*For more information on metadata, please refer to
[obtaining metadata](/developers/developer-guides/vm-specific-tutorials/movevm/creating-move-coin#obtaining-metadata).*
<CodeGroup>
```bash CLI theme={null}
initiad tx move execute 0x1 dex create_pair_script \
--args '["string:name", "string:symbol", "bigdecimal:0.001", "bigdecimal:0.8", "bigdecimal:0.2", "object:0x...", "object:0x...", "u64:100", "u64:100"]' \
--from [key-name] \
--gas auto --gas-adjustment 1.5 --gas-prices 0.015uinit \
--node [rpc-url]:[rpc-port] --chain-id [chain-id]
```
```ts InitiaJS theme={null}
import {
bcs,
RESTClient,
MnemonicKey,
MsgExecute,
Wallet,
} from '@initia/initia.js';
async function main() {
const restClient = new RESTClient('https://rest.testnet.initia.xyz', {
gasPrices: '0.015uinit',
gasAdjustment: '1.5',
});
const key = new MnemonicKey({
mnemonic: 'beauty sniff protect ...',
});
const wallet = new Wallet(restClient, key);
const msgs = [
new MsgExecute(
key.accAddress,
'0x1',
'dex',
'create_pair_script',
[],
[
bcs.string().serialize('name'), // name
bcs.string().serialize('symbol'), // symbol
bcs.bigdecimal().serialize('0.003'), // swap fee
bcs.bigdecimal().serialize('0.2'), // coin a weight
bcs.bigdecimal().serialize('0.8'), // coin b weight
bcs.object().serialize('0x...'), // coin a
bcs.object().serialize('0x...'), // coin b
bcs.u64().serialize(7500000000000), // coin a amount
bcs.u64().serialize(3000000000000), // coin b amount
].map(v => v.toBase64())
),
];
// sign tx
const signedTx = await wallet.createAndSignTx({ msgs });
// send(broadcast) tx
restClient.tx.broadcastSync(signedTx).then(res => console.log(res));
// {
// height: 0,
// txhash: '0F2B255EE75FBA407267BB57A6FF3E3349522DA6DBB31C0356DB588CC3933F37',
// raw_log: '[]'
// }
}
main();
```
</CodeGroup>
## How to Provide Liquidity
### Provide Liquidity
`provide_liquidity` enables you to provide liquidity of both `coin_a` and
`coin_b` in the specific pair. To maximize the LP tokens received and minimize
slippage, provide liquidity in proportion with the current ratio. The Move module
interface is as follows:
```move theme={null}
public entry fun provide_liquidity_script(
account: &signer,
pair: Object<Config>,
coin_a_amount_in: u64,
coin_b_amount_in: u64,
min_liquidity: Option<u64>
)
```
* `pair`: The metadata or object address of pair.
* `coin_a_amount_in` and `coin_b_amount_in`: Amount of token provided for
`coin_a` and `coin_b`.
* `min_liquidity`: Minimum amount of liquidity token to receive. In case that
the actual value is smaller than `min_liquidity`, the transaction will fail.
<CodeGroup>
```bash CLI theme={null}
initiad tx move execute 0x1 dex provide_liquidity_script \
--args '["object:0x...", "u64:100", "u64:100", "option<u64>:100"]' \
--from [key-name] \
--gas auto --gas-adjustment 1.5 --gas-prices 0.015uinit \
--node [rpc-url]:[rpc-port] --chain-id [chain-id]
```
```ts InitiaJS theme={null}
import {
bcs,
RESTClient,
MnemonicKey,
MsgExecute,
Wallet,
} from '@initia/initia.js';
async function main() {
const restClient = new RESTClient('https://rest.testnet.initia.xyz', {
gasPrices: '0.015uinit',
gasAdjustment: '1.5',
});
const key = new MnemonicKey({
mnemonic: 'beauty sniff protect ...',
});
const wallet = new Wallet(restClient, key);
const msgs = [
new MsgExecute(
key.accAddress,
'0x1',
'dex',
'provide_liquidity_script',
[],
[
bcs.object().serialize('0x...'), // pair object
bcs.u64().serialize(7500000000000), // coin a amount
bcs.u64().serialize(3000000000000), // coin b amount
bcs.option(bcs.u64()).serialize(100000000), // min liquidity amount
].map(v => v.toBase64())
),
];
// sign tx
const signedTx = await wallet.createAndSignTx({ msgs });
// send(broadcast) tx
restClient.tx.broadcastSync(signedTx).then(res => console.log(res));
// {
// height: 0,
// txhash: '0F2B255EE75FBA407267BB57A6FF3E3349522DA6DBB31C0356DB588CC3933F37',
// raw_log: '[]'
// }
}
main();
```
</CodeGroup>
### Single Asset Provide Liquidity
Instead of providing both tokens in a pair, you can provide liquidity using only
one token. Internally, half of the token is swapped to the other token in the
pair to provide liquidity, which may result in fees and slippage. The Move
function interface is as follows:
```move theme={null}
public entry fun single_asset_provide_liquidity_script(
account: &signer,
pair: Object<Config>,
provide_coin: Object<Metadata>,
amount_in: u64,
min_liquidity: Option<u64>
)
```
* `pair`: The metadata or object address of pair.
* `provide_coin`: The metadata of the provided coin.
* `amount_in`: The amount of provided coin.
* `min_liquidity`: Minimum amount of liquidity token to receive. In case that
the actual value is smaller than `min_liquidity`, the transaction will fail.
<CodeGroup>
```bash CLI theme={null}
initiad tx move execute 0x1 dex single_asset_provide_liquidity_script \
--args '["object:0x...", "object:0x..", "u64:100", "option<u64>:100"]' \
--from [key-name] \
--gas auto --gas-adjustment 1.5 --gas-prices 0.015uinit \
--node [rpc-url]:[rpc-port] --chain-id [chain-id]
```
```ts InitiaJS theme={null}
import {
bcs,
RESTClient,
MnemonicKey,
MsgExecute,
Wallet,
} from '@initia/initia.js';
async function main() {
const restClient = new RESTClient('https://rest.testnet.initia.xyz', {
gasPrices: '0.015uinit',
gasAdjustment: '1.5',
});
const key = new MnemonicKey({
mnemonic: 'beauty sniff protect ...',
});
const wallet = new Wallet(restClient, key);
const msgs = [
new MsgExecute(
key.accAddress,
'0x1',
'dex',
'single_asset_provide_liquidity_script',
[],
[
bcs.object().serialize('0x...'), // pair object
bcs.object().serialize('0x...'), // provide asset metadata
bcs.u64().serialize(3000000000000), // provide amount
bcs.프로젝트로 돌아가기