From b91dc7064bed433b239738d399e6e850a7b9bf04 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Fri, 26 Apr 2024 18:10:09 +0200 Subject: [PATCH 01/10] Add basic outline for IBC --- src/pages/ibc.mdx | 22 +++++++++++ src/pages/ibc/_meta.json | 6 +++ src/pages/ibc/basic-concepts.mdx | 29 ++++++++++++++ src/pages/ibc/diy-protocol.mdx | 14 +++++++ src/pages/ibc/diy-protocol/_meta.json | 4 ++ .../ibc/diy-protocol/channel-lifecycle.mdx | 39 +++++++++++++++++++ .../ibc/diy-protocol/packet-lifecycle.mdx | 21 ++++++++++ src/pages/ibc/existing-protocols.mdx | 34 ++++++++++++++++ src/pages/ibc/getting-started.mdx | 23 +++++++++++ 9 files changed, 192 insertions(+) create mode 100644 src/pages/ibc.mdx create mode 100644 src/pages/ibc/_meta.json create mode 100644 src/pages/ibc/basic-concepts.mdx create mode 100644 src/pages/ibc/diy-protocol.mdx create mode 100644 src/pages/ibc/diy-protocol/_meta.json create mode 100644 src/pages/ibc/diy-protocol/channel-lifecycle.mdx create mode 100644 src/pages/ibc/diy-protocol/packet-lifecycle.mdx create mode 100644 src/pages/ibc/existing-protocols.mdx create mode 100644 src/pages/ibc/getting-started.mdx diff --git a/src/pages/ibc.mdx b/src/pages/ibc.mdx new file mode 100644 index 00000000..e42b270b --- /dev/null +++ b/src/pages/ibc.mdx @@ -0,0 +1,22 @@ +--- +tags: ["ibc"] +--- + +import Tags from "@/components/Tags"; + + + +# Introduction + +IBC is a protocol that allows different blockchains to communicate with each +other. It is a standard that defines how blockchains can send and receive +messages to each other. This allows for the creation of a network of blockchains +that can interact with each other. + +You can use the IBC protocol as a building block to create your own custom +protocols on top of it, but you can also use existing protocols like the [ICS 20 +token transfer protocol]. In the following sections, we will explain how both of +these work. + +[ICS-20 token transfer protocol]: + https://github.com/cosmos/ibc/blob/main/spec/app/ics-020-fungible-token-transfer/README.md diff --git a/src/pages/ibc/_meta.json b/src/pages/ibc/_meta.json new file mode 100644 index 00000000..bb5ce414 --- /dev/null +++ b/src/pages/ibc/_meta.json @@ -0,0 +1,6 @@ +{ + "basic-concepts": "Basic concepts", + "getting-started": "Getting started", + "existing-protocols": "Using existing protocols", + "diy-protocol": "Build your own protocol" +} diff --git a/src/pages/ibc/basic-concepts.mdx b/src/pages/ibc/basic-concepts.mdx new file mode 100644 index 00000000..cbc6233c --- /dev/null +++ b/src/pages/ibc/basic-concepts.mdx @@ -0,0 +1,29 @@ +--- +tags: ["ibc"] +--- + +import Tags from "@/components/Tags"; + + + +## Basic Concepts + +In order to understand how IBC works, it is important to understand some basic +concepts: + +- **Port**: An identifier that corresponds to a single module on a chain. One + module can have multiple ports. Each contract has its own unique port. +- **Channel**: A connection between two blockchains that allows them to send + messages to each other. Each port can have multiple channels. +- **Relayer**: A service that is responsible for relaying messages between + blockchains. Anyone can run a relayer. +- **Packet**: A piece of binary data that is sent through a channel. It can time + out if it is not delivered within a certain time frame. + +We will go into more detail on these concepts in the later sections, but this +should give you some basic terminology to start with. If you want to learn more +about IBC, you can read the [IBC specification] or check out the [IBC +documentation]. + +[IBC specification]: https://github.com/cosmos/ibc +[IBC documentation]: https://ibc.cosmos.network/main diff --git a/src/pages/ibc/diy-protocol.mdx b/src/pages/ibc/diy-protocol.mdx new file mode 100644 index 00000000..d0de3f6a --- /dev/null +++ b/src/pages/ibc/diy-protocol.mdx @@ -0,0 +1,14 @@ +--- +tags: ["ibc"] +--- + +import Tags from "@/components/Tags"; + + + +# Build your own protocol + +In the following sections, we will guide you through the process of building +your own IBC protocol. We will cover how to establish a channel between two +chains, send and receive packets and how to handle timeouts and +acknowledgements. diff --git a/src/pages/ibc/diy-protocol/_meta.json b/src/pages/ibc/diy-protocol/_meta.json new file mode 100644 index 00000000..80959cc4 --- /dev/null +++ b/src/pages/ibc/diy-protocol/_meta.json @@ -0,0 +1,4 @@ +{ + "channel-lifecycle": "Channel lifecycle", + "packet-lifecycle": "Packet lifecycle" +} diff --git a/src/pages/ibc/diy-protocol/channel-lifecycle.mdx b/src/pages/ibc/diy-protocol/channel-lifecycle.mdx new file mode 100644 index 00000000..2ee48bc1 --- /dev/null +++ b/src/pages/ibc/diy-protocol/channel-lifecycle.mdx @@ -0,0 +1,39 @@ +--- +tags: ["ibc"] +--- + +import Tags from "@/components/Tags"; + + + +# Channel lifecycle + +A channel is a connection between two IBC ports that allows them to send packets +to each other. In this section, we will cover how to establish a channel and how +to close it. Since a channel is a connection between two ports, it can connect +two chain modules, two contracts, or a module and a contract. + +## Establishing a channel + +In order to send packets between two chains, you need to establish a channel +between them. This process involves two calls per chain. They are described +below. Once the channel is established, you can start sending packets through +it, which we will cover in the next section. + +### Channel open + +{/* `ibc_channel_open` called on both chains, explain differences */} + +### Channel connect + +{/* `ibc_channel_connect` called on both chains, explain differences */} + +## Closing a channel + +--- + +Notes: + +- reference basic concepts +- relayer initiates this +- explain ibc_channel_open & ibc_channel_connect diff --git a/src/pages/ibc/diy-protocol/packet-lifecycle.mdx b/src/pages/ibc/diy-protocol/packet-lifecycle.mdx new file mode 100644 index 00000000..eae884cb --- /dev/null +++ b/src/pages/ibc/diy-protocol/packet-lifecycle.mdx @@ -0,0 +1,21 @@ +--- +tags: ["ibc"] +--- + +import Tags from "@/components/Tags"; + + + +# Packet lifecycle + +## Sending a packet + +## Receiving a packet + +### Async acknowledgement + +if implemented until then + +## Receiving a packet acknowledgement + +## Receiving a packet timeout diff --git a/src/pages/ibc/existing-protocols.mdx b/src/pages/ibc/existing-protocols.mdx new file mode 100644 index 00000000..d091a905 --- /dev/null +++ b/src/pages/ibc/existing-protocols.mdx @@ -0,0 +1,34 @@ +--- +tags: ["ibc", "ibc-msg", "transfer", "ics20"] +--- + +import Tags from "@/components/Tags"; + + + +# Using Existing Protocols + +The easiest way to use IBC is to use an already existing protocol. These +protocols can either be implemented by the chain itself or by another contract. + +One example for the former is the `IbcMsg::Transfer` message, which causes an +ICS 20 transfer. This message is included in the CosmWasm standard library and +causes the chain's IBC Transfer module to send tokens to another chain. + +An example for the latter is the Nois protocol. It provides a proxy contract +that handles all the IBC logic for you. For more information on Nois, check the +[Nois documentation](https://docs.nois.network/dapp_devs/use_nois_randomness.html). + +## Example: `IbcMsg::Transfer` + +TODO + +- add example code + +## ADR-8: IBC Callbacks + +TODO + +- needs to be supported by the chain +- two new entrypoints +- needs to be enabled for each message (show example transfer) diff --git a/src/pages/ibc/getting-started.mdx b/src/pages/ibc/getting-started.mdx new file mode 100644 index 00000000..ce034505 --- /dev/null +++ b/src/pages/ibc/getting-started.mdx @@ -0,0 +1,23 @@ +--- +tags: ["ibc"] +--- + +import Tags from "@/components/Tags"; + + + +# Getting started + +To get started, you need to enable the `stargate` feature of the `cosmwasm-std` +crate. This will enable additional functionality that is not available on all +chains, including IBC support. + +```toml +cosmwasm-std = { version = "...", features = ["stargate"] } +``` + +--- + +Notes: + +- add reference to core capabilities section From 55ff202477667b1e358d87d11842bb1602914edb Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Fri, 26 Apr 2024 18:11:02 +0200 Subject: [PATCH 02/10] Add ibc to menu --- src/pages/_meta.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/_meta.json b/src/pages/_meta.json index 617f21ef..3abb35d3 100644 --- a/src/pages/_meta.json +++ b/src/pages/_meta.json @@ -1,6 +1,7 @@ { "index": "Welcome", "core": "CosmWasm Core", + "ibc": "IBC", "sylvia": "Sylvia", "cw-multi-test": "MultiTest", "how-to-doc": "How to doc" From 801665f16b1175225a0bd2d593ec74684477c96a Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Mon, 29 Apr 2024 12:57:57 +0200 Subject: [PATCH 03/10] Add ibc transfer msg info --- src/pages/ibc/existing-protocols.mdx | 36 ++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/pages/ibc/existing-protocols.mdx b/src/pages/ibc/existing-protocols.mdx index d091a905..ffff85e9 100644 --- a/src/pages/ibc/existing-protocols.mdx +++ b/src/pages/ibc/existing-protocols.mdx @@ -1,5 +1,5 @@ --- -tags: ["ibc", "ibc-msg", "transfer", "ics20"] +tags: ["ibc", "ics20"] --- import Tags from "@/components/Tags"; @@ -12,7 +12,7 @@ The easiest way to use IBC is to use an already existing protocol. These protocols can either be implemented by the chain itself or by another contract. One example for the former is the `IbcMsg::Transfer` message, which causes an -ICS 20 transfer. This message is included in the CosmWasm standard library and +ICS20 transfer. This message is included in the CosmWasm standard library and causes the chain's IBC Transfer module to send tokens to another chain. An example for the latter is the Nois protocol. It provides a proxy contract @@ -21,9 +21,35 @@ that handles all the IBC logic for you. For more information on Nois, check the ## Example: `IbcMsg::Transfer` -TODO - -- add example code +To initiate an ICS20 transfer, you need to attach an `IbcMsg::Transfer` message +to your contract response like this: + +```rust +// construct the transfer message +let msg = IbcMsg::Transfer { + channel_id, + to_address, + amount: Coin::new(123u128, "ucosm"), + timeout: env.block.time.plus_seconds(PACKET_LIFETIME).into(), + memo: None, +}; + +// attach the message and return the response +Response::new().add_message(msg) +``` + +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 of tokens to send. The `timeout` can either be a +timestamp or a block height. 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. + +[packet-forward-middleware]: + https://github.com/cosmos/ibc-apps/tree/main/middleware/packet-forward-middleware ## ADR-8: IBC Callbacks From 868b97377782d0585ce9546755eb92e44e72c3fb Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Mon, 29 Apr 2024 12:58:09 +0200 Subject: [PATCH 04/10] Reorder ibc sections --- src/pages/ibc/_meta.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ibc/_meta.json b/src/pages/ibc/_meta.json index bb5ce414..7135e07f 100644 --- a/src/pages/ibc/_meta.json +++ b/src/pages/ibc/_meta.json @@ -1,6 +1,6 @@ { - "basic-concepts": "Basic concepts", "getting-started": "Getting started", + "basic-concepts": "Basic concepts", "existing-protocols": "Using existing protocols", "diy-protocol": "Build your own protocol" } From d45aaa6f3ed677eedae47cc0d1b7d5d7ed38978a Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Mon, 29 Apr 2024 13:06:25 +0200 Subject: [PATCH 05/10] Fix ibc concepts --- src/pages/ibc/basic-concepts.mdx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pages/ibc/basic-concepts.mdx b/src/pages/ibc/basic-concepts.mdx index cbc6233c..c5d46f96 100644 --- a/src/pages/ibc/basic-concepts.mdx +++ b/src/pages/ibc/basic-concepts.mdx @@ -13,9 +13,10 @@ concepts: - **Port**: An identifier that corresponds to a single module on a chain. One module can have multiple ports. Each contract has its own unique port. -- **Channel**: A connection between two blockchains that allows them to send - messages to each other. Each port can have multiple channels. -- **Relayer**: A service that is responsible for relaying messages between +- **Channel**: A connection between two ports on different blockchains that + allows them to send packets to each other. Each port can have multiple + channels. +- **Relayer**: A service that is responsible for relaying packets between blockchains. Anyone can run a relayer. - **Packet**: A piece of binary data that is sent through a channel. It can time out if it is not delivered within a certain time frame. From af59d6972c20b95b6cc0ba2e23b809705599d55f Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Mon, 29 Apr 2024 16:48:44 +0200 Subject: [PATCH 06/10] Remove tags --- src/pages/ibc/basic-concepts.mdx | 4 ---- src/pages/ibc/diy-protocol.mdx | 4 ---- src/pages/ibc/diy-protocol/channel-lifecycle.mdx | 4 ---- src/pages/ibc/diy-protocol/packet-lifecycle.mdx | 4 ---- src/pages/ibc/existing-protocols.mdx | 4 +--- src/pages/ibc/getting-started.mdx | 4 ---- 6 files changed, 1 insertion(+), 23 deletions(-) diff --git a/src/pages/ibc/basic-concepts.mdx b/src/pages/ibc/basic-concepts.mdx index c5d46f96..4c5be099 100644 --- a/src/pages/ibc/basic-concepts.mdx +++ b/src/pages/ibc/basic-concepts.mdx @@ -2,10 +2,6 @@ tags: ["ibc"] --- -import Tags from "@/components/Tags"; - - - ## Basic Concepts In order to understand how IBC works, it is important to understand some basic diff --git a/src/pages/ibc/diy-protocol.mdx b/src/pages/ibc/diy-protocol.mdx index d0de3f6a..7252f9e9 100644 --- a/src/pages/ibc/diy-protocol.mdx +++ b/src/pages/ibc/diy-protocol.mdx @@ -2,10 +2,6 @@ tags: ["ibc"] --- -import Tags from "@/components/Tags"; - - - # Build your own protocol In the following sections, we will guide you through the process of building diff --git a/src/pages/ibc/diy-protocol/channel-lifecycle.mdx b/src/pages/ibc/diy-protocol/channel-lifecycle.mdx index 2ee48bc1..5a36b2e9 100644 --- a/src/pages/ibc/diy-protocol/channel-lifecycle.mdx +++ b/src/pages/ibc/diy-protocol/channel-lifecycle.mdx @@ -2,10 +2,6 @@ tags: ["ibc"] --- -import Tags from "@/components/Tags"; - - - # Channel lifecycle A channel is a connection between two IBC ports that allows them to send packets diff --git a/src/pages/ibc/diy-protocol/packet-lifecycle.mdx b/src/pages/ibc/diy-protocol/packet-lifecycle.mdx index eae884cb..b728278e 100644 --- a/src/pages/ibc/diy-protocol/packet-lifecycle.mdx +++ b/src/pages/ibc/diy-protocol/packet-lifecycle.mdx @@ -2,10 +2,6 @@ tags: ["ibc"] --- -import Tags from "@/components/Tags"; - - - # Packet lifecycle ## Sending a packet diff --git a/src/pages/ibc/existing-protocols.mdx b/src/pages/ibc/existing-protocols.mdx index ffff85e9..166a53a6 100644 --- a/src/pages/ibc/existing-protocols.mdx +++ b/src/pages/ibc/existing-protocols.mdx @@ -2,9 +2,7 @@ tags: ["ibc", "ics20"] --- -import Tags from "@/components/Tags"; - - +import { Callout } from "nextra/components"; # Using Existing Protocols diff --git a/src/pages/ibc/getting-started.mdx b/src/pages/ibc/getting-started.mdx index ce034505..7b16b620 100644 --- a/src/pages/ibc/getting-started.mdx +++ b/src/pages/ibc/getting-started.mdx @@ -2,10 +2,6 @@ tags: ["ibc"] --- -import Tags from "@/components/Tags"; - - - # Getting started To get started, you need to enable the `stargate` feature of the `cosmwasm-std` From da93f9e8df38e37b6abf8c79fd30185666c08c54 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Tue, 30 Apr 2024 15:25:18 +0200 Subject: [PATCH 07/10] Start working on ADR8 docs --- src/pages/ibc/existing-protocols.mdx | 100 ++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 11 deletions(-) diff --git a/src/pages/ibc/existing-protocols.mdx b/src/pages/ibc/existing-protocols.mdx index 166a53a6..8e825f89 100644 --- a/src/pages/ibc/existing-protocols.mdx +++ b/src/pages/ibc/existing-protocols.mdx @@ -4,18 +4,19 @@ tags: ["ibc", "ics20"] import { Callout } from "nextra/components"; -# Using Existing Protocols +# Using existing protocols The easiest way to use IBC is to use an already existing protocol. These protocols can either be implemented by the chain itself or by another contract. One example for the former is the `IbcMsg::Transfer` message, which causes an ICS20 transfer. This message is included in the CosmWasm standard library and -causes the chain's IBC Transfer module to send tokens to another chain. +causes the chain's IBC transfer module to send tokens to another chain. An example for the latter is the Nois protocol. It provides a proxy contract that handles all the IBC logic for you. For more information on Nois, check the [Nois documentation](https://docs.nois.network/dapp_devs/use_nois_randomness.html). +We will later cover how to implement your own IBC protocol. ## Example: `IbcMsg::Transfer` @@ -27,7 +28,7 @@ to your contract response like this: let msg = IbcMsg::Transfer { channel_id, to_address, - amount: Coin::new(123u128, "ucosm"), + amount: Coin::new(123u128, "ucoin"), timeout: env.block.time.plus_seconds(PACKET_LIFETIME).into(), memo: None, }; @@ -39,20 +40,97 @@ Response::new().add_message(msg) 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 of tokens to send. The `timeout` can either be a -timestamp or a block height. 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. +[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. [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 ## ADR-8: IBC Callbacks +When you send an ICS20 transfer as described above, you do not get any feedback +on whether the transfer was successful or not and the destination does not get +informed of its newfound wealth. To solve this problem, the ADR-8 specification +was created. On the source chain, it provides callbacks when an IBC packet was +acknowledged or timed out. On the destination chain, it triggers callbacks when +a packet is received. + + + To receive callbacks, the chain needs to support IBC Callbacks for the message + type. + + +### Enabling IBC Callbacks for a message + +You need to explicitly opt-in to IBC Callbacks for each message. In order to do +this, you need to add some metadata to the message, including who should receive +the callbacks. + + + The exact data format and how to add it to the message can vary, but for the + `IbcMsg::Transfer` message, this data is in JSON format and needs to be added + to the `memo` field. + + +To make this as easy as possible, we provide a helper type `IbcCallbackRequest` +that you can use to generate the JSON: + +```rust +let _ = IbcMsg::Transfer { + to_address, + channel_id, + amount: Coin::new(10u32, "ucoin"), + timeout: Timestamp::from_seconds(12345).into(), + memo: Some(to_json_string(&IbcCallbackRequest::both(IbcSrcCallback { + address: env.contract.address, + gas_limit: None, + }, IbcDstCallback { + address: to_address.clone(), + gas_limit: None, + })).unwrap()), +}; +``` + +As you can see, you can request callbacks for both the source and destination +chain. However, you can also request callbacks for only one of them. For this, +you need to provide the address that should receive the callback and you can +optionally set a gas limit for the callback execution. Please take a look at the +`IbcCallbackRequest` docs for more information. + + + The `address` of the source callback always needs to be the contract address + that sends the message (`env.contract.address`). Otherwise, the callback will + error and the contract will not be called. + + +### Entrypoints + TODO -- needs to be supported by the chain - two new entrypoints -- needs to be enabled for each message (show example transfer) + - `ibc_source_chain_callback` + - `ibc_destination_chain_callback` + +--- + +Notes: + +- add link to IbcCallbackRequest docs when merged and deployed From 1658c70367e3dd6283b0eef63c88fb48a4a2fba8 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Tue, 30 Apr 2024 15:30:51 +0200 Subject: [PATCH 08/10] Improve wording --- src/pages/ibc/basic-concepts.mdx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/ibc/basic-concepts.mdx b/src/pages/ibc/basic-concepts.mdx index 4c5be099..2a41857d 100644 --- a/src/pages/ibc/basic-concepts.mdx +++ b/src/pages/ibc/basic-concepts.mdx @@ -17,10 +17,10 @@ concepts: - **Packet**: A piece of binary data that is sent through a channel. It can time out if it is not delivered within a certain time frame. -We will go into more detail on these concepts in the later sections, but this -should give you some basic terminology to start with. If you want to learn more -about IBC, you can read the [IBC specification] or check out the [IBC -documentation]. +We will go into more detail on how these concepts are related to CosmWasm in the +later sections, but this should give you some basic terminology to start with. +If you want to learn more about IBC, you can read the [IBC specification] or +check out the [IBC documentation]. [IBC specification]: https://github.com/cosmos/ibc [IBC documentation]: https://ibc.cosmos.network/main From bd1be17de55f33a2a3bfa25defc45067cc093e36 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Fri, 3 May 2024 12:35:14 +0200 Subject: [PATCH 09/10] Fixes --- src/pages/ibc.mdx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pages/ibc.mdx b/src/pages/ibc.mdx index e42b270b..3c911e85 100644 --- a/src/pages/ibc.mdx +++ b/src/pages/ibc.mdx @@ -2,10 +2,6 @@ tags: ["ibc"] --- -import Tags from "@/components/Tags"; - - - # Introduction IBC is a protocol that allows different blockchains to communicate with each @@ -14,7 +10,7 @@ messages to each other. This allows for the creation of a network of blockchains that can interact with each other. You can use the IBC protocol as a building block to create your own custom -protocols on top of it, but you can also use existing protocols like the [ICS 20 +protocols on top of it, but you can also use existing protocols like the [ICS-20 token transfer protocol]. In the following sections, we will explain how both of these work. From 8e9092089460420824f25f9087e68ac9c3e34d37 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Fri, 3 May 2024 12:47:54 +0200 Subject: [PATCH 10/10] Use template for TransferMsg example --- src/pages/ibc/existing-protocols.mdx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/pages/ibc/existing-protocols.mdx b/src/pages/ibc/existing-protocols.mdx index 8e825f89..fb18893e 100644 --- a/src/pages/ibc/existing-protocols.mdx +++ b/src/pages/ibc/existing-protocols.mdx @@ -23,18 +23,18 @@ We will later cover how to implement your own IBC protocol. To initiate an ICS20 transfer, you need to attach an `IbcMsg::Transfer` message to your contract response like this: -```rust +```rust template="execute" // construct the transfer message let msg = IbcMsg::Transfer { - channel_id, - to_address, + channel_id: "channel-0".to_string(), + to_address: "cosmos1exampleaddress".to_string(), amount: Coin::new(123u128, "ucoin"), - timeout: env.block.time.plus_seconds(PACKET_LIFETIME).into(), + timeout: env.block.time.plus_seconds(60).into(), memo: None, }; // attach the message and return the response -Response::new().add_message(msg) +Ok(Response::new().add_message(msg)) ``` The `channel_id` is the identifier of the channel you want to use for the @@ -93,10 +93,12 @@ the callbacks. To make this as easy as possible, we provide a helper type `IbcCallbackRequest` that you can use to generate the JSON: +{/* TODO: add `template="execute"` once IBC Callbacks are merged */} + ```rust let _ = IbcMsg::Transfer { - to_address, - channel_id, + to_address: "cosmos1exampleaddress".to_string(), + channel_id: "channel-0".to_string(), amount: Coin::new(10u32, "ucoin"), timeout: Timestamp::from_seconds(12345).into(), memo: Some(to_json_string(&IbcCallbackRequest::both(IbcSrcCallback {