Skip to content

Commit a3f21e5

Browse files
authored
Fix IBC destination callback example (#265)
2 parents ee90710 + 8d48acd commit a3f21e5

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/pages/ibc/extensions/callbacks.mdx

+13-9
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ This is how you can implement the `ibc_destination_callback` entrypoint:
202202
</Callout>
203203

204204
```rust template="core"
205-
use ibc::apps::transfer::types::packet::PacketData as TransferPacketData;
205+
use ibc::apps::transfer::types::proto::transfer::v2::FungibleTokenPacketData;
206+
use std::str::FromStr;
206207

207208
#[cfg_attr(not(feature = "library"), entry_point)]
208209
pub fn ibc_destination_callback(
@@ -224,7 +225,7 @@ pub fn ibc_destination_callback(
224225
// but not to whom it is going, how much and what denom.
225226

226227
// Parse the packet data to get that information:
227-
let packet_data: TransferPacketData = from_json(&msg.packet.data)?;
228+
let packet_data: FungibleTokenPacketData = from_json(&msg.packet.data)?;
228229

229230
// The receiver should be a valid address on this chain.
230231
// Remember, we are on the destination chain.
@@ -236,17 +237,20 @@ pub fn ibc_destination_callback(
236237
);
237238

238239
// We only care about this chain's native token in this example.
239-
// The `packet_data.token.denom` is formatted as `{port id}/{channel id}/{denom}`,
240+
// The `packet_data.denom` is formatted as `{port id}/{channel id}/{denom}`,
240241
// where the port id and channel id are the source chain's identifiers.
241-
// Assuming we are running this on Neutron and only want to handle NTRN tokens,
242-
// the denom should look like this:
243-
let ntrn_denom = format!(
242+
// Please note that the denom is not formatted like that when you transfer untrn
243+
// from Neutron to some other chain. In that case, the denom is just the native
244+
// token of the source chain (untrn).
245+
// That being said, assuming we are running this on Neutron and only want to
246+
// handle NTRN tokens, the denom should look like this:
247+
let ntrn_denom_on_source_chain = format!(
244248
"{}/{}/untrn",
245249
msg.packet.src.port_id, msg.packet.src.channel_id
246250
);
247251
ensure_eq!(
248-
packet_data.token.denom.to_string(),
249-
ntrn_denom,
252+
packet_data.denom,
253+
ntrn_denom_on_source_chain,
250254
StdError::generic_err("only want to handle NTRN tokens")
251255
);
252256

@@ -255,7 +259,7 @@ pub fn ibc_destination_callback(
255259
let msg = BankMsg::Send {
256260
to_address: "neutron155exr8rqjrknusllpzxdfvezxr8ddpqehj9g9d".to_string(),
257261
// this panics if the amount is too large
258-
amount: coins(packet_data.token.amount.as_ref().as_u128(), "untrn"),
262+
amount: coins(u128::from_str(&packet_data.amount).unwrap(), "untrn"),
259263
};
260264

261265
Ok(IbcBasicResponse::new()

src/pages/tutorial/cw-contract/funds.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ of cryptocurrencies. It is not the same, but crypto assets, or as we often call
77
very closely connected to the blockchain. CosmWasm has a notion of a native token. Native tokens are
88
assets managed by the blockchain core instead of smart contracts. Often such assets have some
99
special meaning, like being used for paying
10-
[gas fees](https://docs.cosmos.network/v0.52/learn/beginner/gas-fees) or
10+
[gas fees](https://docs.cosmos.network/v0.53/learn/beginner/gas-fees) or
1111
[staking](https://en.wikipedia.org/wiki/Proof_of_stake) for consensus algorithm, but can be just
1212
arbitrary assets.
1313

0 commit comments

Comments
 (0)