Basic IBC Transfer Examples
CLI Transfer Command
Neutron uses the standard IBC transfer CLI command structure. The Transfer module wraps the standard IBC transfer but maintains CLI compatibility:transfer
: Source port (always “transfer” for token transfers)channel-0
: Source channel ID on Neutroncosmos1recipient...
: Recipient address on destination chain1000untrn
: Amount and denomination to transfer--timeout-height
: Block height timeout (0-0 for timestamp-only)--timeout-timestamp
: Unix timestamp for timeout (nanoseconds since unix epoch)--memo
: Optional memo field for additional data
The CLI command uses the standard IBC transfer interface. Neutron’s enhancements (contract detection, callbacks, enhanced responses) are handled automatically by the Transfer module wrapper.
CosmWasm Transfer Integration
Send IBC transfers from a smart contract usingNeutronMsg
. The exact structure depends on the neutron-sdk version:
The exact field names and types in
NeutronMsg::IbcTransfer
depend on your neutron-sdk version. Always refer to the neutron-sdk documentation for the correct structure. The fields shown here match the protobuf definition in neutron.transfer.MsgTransfer
.Handling Transfer Callbacks
Implement Sudo callbacks to handle transfer acknowledgments and timeouts. The Transfer module calls contracts using the Contract Manager’s sudo message format:The sudo message structures shown here match the exact format used by Neutron’s Contract Manager module. The
RequestPacket
structure corresponds to the IBC channeltypes.Packet
that was originally sent.Advanced Transfer Features
Multi-hop Transfer (Packet Forwarding)
Route transfers through Neutron to other chains using packet forwarding middleware:- Tokens sent from origin chain to Neutron
- Neutron automatically forwards to final destination
- Memo specifies the final receiver and routing information
Packet forwarding functionality depends on packet forwarding middleware being configured in the IBC stack. The exact availability and configuration may vary by network setup.
IBC Hooks: Contract Execution via Transfer
Call smart contracts on Neutron by sending IBC transfers with contract execution memos. The receiver address should be the contract address:The
receiver
field should be set to the contract address. The IBC hooks middleware intercepts the transfer and executes the contract with the specified message and transferred funds.JavaScript Example with IBC Hooks
- Transfer sent to Neutron with contract address as receiver
- IBC hooks middleware intercepts the transfer
- Funds are sent to an intermediate account derived from the sender
- Contract is executed with the transferred funds and specified message
- Contract receives funds in its balance and executes the provided message
When using IBC hooks, the contract should be designed to handle execute messages that may come with transferred funds. The exact integration pattern depends on your specific contract logic.
Transfer Module Integration
The Transfer module automatically detects smart contracts and provides enhanced functionality for IBC transfers.Contract Detection
The module determines if a sender is a smart contract using:Enhanced Transfer Response
When contracts send IBC transfers, they receive enhanced response information:Message Structure
The Transfer module extends the standard IBC transfer message with fee information:Contract-Specific Processing
Fee Validation and Locking
For contract senders, the Transfer module:- Validates Fees: Calls
msg.Fee.Validate()
to ensure proper fee structure - Locks Fees: Uses
FeeKeeper.LockFees()
to secure fees for packet processing
Automatic Callbacks
When IBC packets are acknowledged or timeout, the Transfer module automatically:- Checks Contract Status: Verifies if the original sender was a contract
- Distributes Fees: Calls appropriate fee distribution functions
- Sends Callback: Uses
sudoKeeper.Sudo()
to notify the contract
Callback Mechanism
The Transfer module implements callbacks for contract senders:Acknowledgement Processing
Timeout Processing
Error Handling
The Transfer module implements robust error handling:Callback Failures
Failed Sudo calls are logged but do not affect IBC processing:- Acknowledgement/timeout processing continues regardless of callback success
- Fee distribution occurs independently of callback results
- IBC packet processing is not blocked by contract errors
Fee Processing
Fee operations are handled separately from callbacks:- Fee locking occurs before packet transmission
- Fee distribution happens regardless of callback outcomes
- Contract fee validation only applies to contract senders
Integration Requirements
To integrate with the Transfer module, contracts must:Message Format
Refer to the Contract Manager module documentation for:- Callback message structure and format
- Request ID handling and correlation
- Sudo message specifications
Contract Manager Dependency: The specific format and content of callback messages are determined by the Contract Manager module’s
PrepareSudoCallbackMessage()
function. Contract implementations must align with Contract Manager specifications.Fee Management
Refer to the Fee Refunder module documentation for:- Fee structure requirements (
neutron.feerefunder.Fee
) - Balance requirements for fee payment
- Fee distribution mechanisms
Fee Refunder Dependency: Fee validation, locking, and distribution behavior are implemented by the Fee Refunder module. Contract fee handling must comply with Fee Refunder specifications.
Module Queries
The Transfer module delegates all queries to the standard IBC Transfer implementation:- DenomTrace: Query denomination trace information
- DenomTraces: Query all denomination traces
- Params: Query transfer module parameters
- DenomHash: Query denomination hash information
Best Practices
- Handle Callback Failures: Implement appropriate error handling for cases where callbacks may not be received
- Use Response Information: Store
sequence_id
andchannel
from transfer responses for correlation - Implement Timeouts: Set appropriate timeout values for your use case
- Fee Management: Ensure sufficient balance for fee requirements when sending transfers
- Refer to Dependencies: Check Contract Manager and Fee Refunder module documentation for integration specifics