IBC Transfers
Terra has full IBC transfer capabilities through both feather.js and Terra Station. Although IBC functionality is not readily exposed through Terra Station’s front end, it can be fully incorporated into any dApp. It is up to a dApp’s front end to initiate IBC transfers.
MsgTransfer
feather.js exports a MsgTransfer class that can be used to construct IBC transfers.
_9new MsgTransfer(_9 'transfer', // IBC port_9 'channel-1', // Outbound channel (Osmosis)_9 new Coin('uluna', '1000000'), // 1 LUNA_9 'terra1cvw8sundusurqajhurpcfk7yvuzlh92cvkpy28', // Source Address on Terra_9 'osmo1cl4qw7u35uf77l4scjtv0qej8ycevu4mrdpvmg', // Destination address on Osmosis_9 undefined, // Timeout block height (optional)_9 (Date.now() + 60 * 1000) * 1e6, // Timeout timestamp (in nanoseconds) relative to the current block timestamp._9);
Supported Channels
Channels are defined when a relayer is set up between Terra and an external chain. For each new connected chain the channel ID is incremented.
You can use Map of Zones to find the available channels and their IDs.
Derive Cosmos chain addresses from a Terra address
Cosmos SDK based blockchains use bech32 to encode the public key for display. Assuming the same private key is used on multiple Cosmos SDK chains it is possible to decode a Terra address and generate the corresponding public key on another chain.
Here's a quick example using the bech32 JavaScript library:
_5import { bech32 } from 'bech32';_5_5const terraAddress = 'terra1cvw8sundusurqajhurpcfk7yvuzlh92cvkpy28';_5const decodedAddress = bech32.decode(terraAddress);_5const osmosisAddress = bech32.encode('osmo', decodedAddress.words);
Complete example
The following example demonstrates how to send 1 LUNA from Terra to the Osmosis blockchain.
_34import {_34 LCDClient,_34 MnemonicKey,_34 MsgTransfer,_34 Coin,_34} from '@terra-money/feather.js';_34_34// const lcd = new LCDClient(...);_34_34const mk = new MnemonicKey({_34 mnemonic:_34 'satisfy adjust timber high purchase tuition stool faith fine install that you unaware feed domain license impose boss human eager hat rent enjoy dawn',_34});_34_34const wallet = lcd.wallet(mk);_34_34// Send 1 LUNA to the Osmosis blockchain._34const transfer = new MsgTransfer(_34 'transfer',_34 'channel-1',_34 new Coin('uluna', '1000000'),_34 'terra1cvw8sundusurqajhurpcfk7yvuzlh92cvkpy28',_34 'osmo1cl4qw7u35uf77l4scjtv0qej8ycevu4mrdpvmg',_34 undefined,_34 (Date.now() + 60 * 1000) * 1e6,_34);_34_34const tx = await wallet.createAndSignTx({_34 msgs: [transfer],_34 chainID: 'pisco-1',_34});_34const result = await lcd.tx.broadcast(tx, 'pisco-1');_34_34console.log(result);
Instructions for initializing LCDClient can be found here.