-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
90 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
tags: ["ibc"] | ||
--- | ||
|
||
import { Callout, Tabs } from "nextra/components"; | ||
|
||
# Extensions | ||
|
||
In this chapter we will cover various extensions to IBC that are not part of the core IBC protocol, | ||
but can be used in combination with either your own protocol or an existing one (like | ||
[ICS20](./ics20)). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
tags: ["ibc", "ics20", "entrypoints"] | ||
--- | ||
|
||
import { Callout, Tabs } from "nextra/components"; | ||
|
||
# ICS20: Fungible Token Transfer | ||
|
||
The [ICS20] protocol defines a standard for transferring fungible tokens between two chains using | ||
IBC. It is one of the most widely used IBC protocols and is supported by pretty much all chains in | ||
the Cosmos. | ||
|
||
To initiate an ICS20 transfer from inside a contract, you need to attach an `IbcMsg::Transfer` | ||
message to your contract response like this: | ||
|
||
```rust template="execute" | ||
// construct the transfer message | ||
let msg = IbcMsg::Transfer { | ||
channel_id: "channel-0".to_string(), | ||
to_address: "cosmos1exampleaddress".to_string(), | ||
amount: Coin::new(123u128, "ucoin"), | ||
timeout: env.block.time.plus_seconds(60).into(), | ||
memo: None, | ||
}; | ||
|
||
// attach the message and return the response | ||
Ok(Response::new().add_message(msg)) | ||
``` | ||
|
||
Sending this message causes an IBC transfer of the given `amount` from your contract to the | ||
destination chain at the other end of the given channel. | ||
|
||
The `channel_id` is the identifier of the channel you want to use for the transfer. Which channel | ||
that should be depends on the source and destination chain. You can find out the correct channel ID | ||
using a [block explorer](https://www.mintscan.io/cosmos/relayers). | ||
|
||
The `to_address` is the address on the _destination chain_ that should receive the tokens. | ||
|
||
The `amount` is the number and denomination of tokens to send. On the destination chain, the same | ||
amount will be received, but the denomination will be of the form `ibc/HASH`, where `HASH` is a | ||
SHA256 hash uniquely identifying the channel and the source chain denomination. To learn more about | ||
this, take a look at the [Cosmos Developer Portal]. | ||
|
||
The `timeout` can either be a timestamp or a block height, as measured on the destination chain. It | ||
is used to prevent the transfer from being stuck in limbo if the destination chain does not receive | ||
the packet. | ||
|
||
The `memo` is an optional field that can be used to attach a message to the transfer. It is often | ||
used for additional functionality like [packet-forward-middleware] or | ||
[IBC Callbacks](./extensions/callbacks). | ||
|
||
[ICS20]: https://github.com/cosmos/ibc/blob/main/spec/app/ics-020-fungible-token-transfer/README.md | ||
[packet-forward-middleware]: | ||
https://github.com/cosmos/ibc-apps/tree/main/middleware/packet-forward-middleware | ||
[Cosmos Developer Portal]: | ||
https://tutorials.cosmos.network/tutorials/6-ibc-dev/#understand-ibc-denoms |