# IBC 转账 (IBC transfers)

利用 Namada 命令行界面（cli），可以通过命令 `namadac ibc-transfer` 进行 ibc 转账。前提假设是已经创建了一个通道，并且 Hermes 在两个节点上运行着正确的配置。

<br>

为了使用 Namada 的 `ibc-transfer` 命令进行 IBC 转账，我们需要知道每个实例的 `base-dir` 和 `node`（以及其他转账参数）。`base-dir` 是每个节点的基本目录，详见 [base-dir](/namada-docs-chinese/yun-ying-zhi-nan-operators-guide/yun-xing-wan-zheng-jie-dian-runningafull-node/ji-ben-mu-lu-base-directory.md) 获取更多信息。`node` 是中继器的 `rpc_addr`。你可以运行

```
grep "rpc_addr" ${HERMES_CONFIG}
```

来查找地址。

{% hint style="warning" %}
仅对本地节点 (For the local node ONLY)

要查找链 A 的账本地址，可以运行以下命令：

```
export BASE_DIR_A = "${HERMES}/data/namada-a/.namada"
export LEDGER_ADDRESS_A = "$(grep "rpc_address" ${BASE_DIR_A}/${CHAIN_A_ID}/setup/validator-0/.namada/${CHAIN_A_ID}/config.toml)"
```

{% endhint %}

此链的 channel-id 将取决于创建通道的顺序。由于我们只打开了一个通道， `channel-id`  是 `channel-0`，但随着更多通道的创建，这些 channel-id 会按索引递增。 channel-id 应由中继器通知。

假设打开的通道是 channel-0，可以通过运行以下命令将其保存在环境变量中：

```
export CHANNEL_ID = "channel-0"
```

可以通过以下方式实现从链 A 的跨区块链转账：

```
namadac --base-dir ${BASE_DIR_A}
    ibc-transfer \
        --amount ${AMOUNT} \
        --source ${SOURCE_ALIAS} \
        --receiver ${RECEIVER_RAW_ADDRESS} \
        --token ${TOKEN_ALIAS} \
        --channel-id ${CHANNEL_ID} \
        --node ${LEDGER_ADDRESS_A}
```

其中，上述的 `${VARIABLE}` 变量必须用适当的值替换。可以通过 `namadaw --base-dir ${BASE_DIR_B} address find --alias ${RECEIVER}`找到接收者的原始地址。

例如：

```
namadac --base-dir ${BASE_DIR_A}
    ibc-transfer \
    --amount 100 \
    --source albert \
    --receiver atest1d9khqw36g56nqwpkgezrvvejg3p5xv2z8y6nydehxprygvp5g4znj3phxfpyv3pcgcunws2x0wwa76 \
    --token nam \
    --channel-id channel-0 \
    --node 127.0.0.1:27657
```

交易提交后，中继器需要将数据包中继到另一条链。这是由运行 Hermes 的中继器自动完成的。如果数据包从未成功中继，则资金将在超时后返回给发送方。在[space](https://specs.namada.net/interoperability/ibc)说明中查看更多信息。

***

## 从基于 Cosmos-SDK 的链上转回资产 (Transferring assets back from Cosmos-SDK based chains)

当资产被转移到基于 Cosmos-SDK 的链时，ibc 转账将按照上述方式进行。然而，从 cosmos-based 链转回时，显然 `namadac ibc-transfer` 命令将不起作用。相反，您会想要使用 [`gaiad`](https://github.com/cosmos/gaia)。

```
gaiad tx ibc-transfer transfer transfer ${CHANNEL_ID} ${RECEIVER_RAW_ADDRESS} ${AMOUNT}${IBC_TOKEN_ADDRESS} --from ${COSMOS_ALIAS} --node ${COSMOS_RPC_ENDPOINT} --fees 5000uatom
```

例如：

```
gaiad tx ibc-transfer transfer transfer channel-0 atest1d9khqw368qcyx3jxxu6njs2yxs6y2sjyxdzy2d338pp5yd35g9zrv334gceng3z9gvmryv2pfdddt4 10ibc/281545A262215A2D7041CE1B518DD4754EC7097A1C937BE9D9AB6F1F11B452DD --from my-cosmos-address --node https://rpc.sentry-01.theta-testnet.polypore.xyz:443 --fees 5000uatom
```


---

# 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://tantalum666.gitbook.io/namada-docs-chinese/yong-hu-zhi-nan-user-guide/ibc-zhuan-zhang-ibc-transfers.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.
