Sending Move Coin
Overview
This tutorial will guide you through the process of sending coins on the Initia blockchain, covering both Initia (Layer 1) and Minitias (Layer 2). Whether you're testing out transactions in a development environment or preparing to deploy your application, understanding how to manage and transfer tokens is essential.
Tutorial
Step 1: Acquire Coins from the Faucet (Optional)
If your account doesn't already hold tokens, you'll need to obtain some Testnet INIT tokens from the Initia Faucet. This step is crucial for testing transactions without using real assets.
Step 2: Check Balances
Before initiating a transaction, it's good practice to check the account balances. This verification ensures that the account has sufficient funds for the transaction and the associated gas fees.
> initiad query bank balances [addr] \
--node [rpc-url]:[rpc-port]Example Response:
balances:
- amount: "100000000"
denom: uinit
pagination:
next_key: null
total: "0"import { LCDClient, MnemonicKey } from '@initia/initia.js';
async function checkBalances() {
const lcd = new LCDClient('[rest-url]', {
gasPrices: '0.15uinit',
gasAdjustment: '1.5',
});
const key = new MnemonicKey({
mnemonic:
'beauty sniff protect ...',
});
const receiver = 'init10v3kg8hfvsj6tklfj5aam9ya5lmvtl9snqsawg';
const senderBalances = await lcd.bank.balance(key.accAddress);
const receiverBalances = await lcd.bank.balance(receiver);
console.log('sender balances:', senderBalances[0]);
// sender balances: Coins {
// _coins: {
// uinit: Coin { denom: 'uinit', amount: '100000000', isDecimal: false }
// }
// }
console.log('receiver balances:', receiverBalances[0]);
// receiver balances: Coins { _coins: {} }
}
checkBalances();Step 3: Execute a Send Transaction
To send coins to another address, use the following command, adjusting the parameters as needed for your specific transaction:
> initiad tx bank send [key-name] [addr] 100000uinit \
--gas auto --gas-adjustment 1.5 --gas-prices 0.15uinit \
--node [rpc-url]:[rpc-port] --chain-id [chain-id]The CLI will provide a gas estimate and transaction details. Review these carefully before confirming the transaction.
gas estimate: 909531
auth_info:
fee:
amount:
- amount: "136430"
denom: uinit
...
txhash: A33D7F2E8472506FCC8C1C480817C040B19D0340766B861781D5A822AD55D882import { LCDClient, MnemonicKey, MsgSend, Wallet } from '@initia/initia.js';
async function sendCoin() {
const lcd = new LCDClient('[rest-url]', {
gasPrices: '0.15uinit',
gasAdjustment: '1.5',
});
const key = new MnemonicKey({
mnemonic:
'beauty sniff protect ...',
});
const wallet = new Wallet(lcd, key);
const receiver = 'init10v3kg8hfvsj6tklfj5aam9ya5lmvtl9snqsawg';
const msgs = [
new MsgSend(
key.accAddress, // sender
receiver, // receiver
'100000uinit' // amount
),
];
// sign tx
const signedTx = await wallet.createAndSignTx({ msgs });
// send(broadcast) tx
lcd.tx.broadcastSync(signedTx).then(res => console.log(res));
// {
// height: 0,
// txhash: 'EA9021C165FF676820C4FB3C01DD88626FCE0202B1511F0DD42FB6A58C92C730',
// raw_log: '[]'
// }
}
sendCoin();Step 4: Verify Balances Post-Transaction
After sending the coin, verify both the sender's and receiver's balances to confirm the transaction's success.
> initiad query bank balances [addr] \
--node [rpc-url]:[rpc-port]Example Response:
balances:
- amount: "99763570"
denom: uinit
pagination:
next_key: null
total: "0"import { LCDClient, MnemonicKey } from '@initia/initia.js';
async function checkBalances() {
const lcd = new LCDClient('[rest-url]', {
gasPrices: '0.15uinit',
gasAdjustment: '1.5',
});
const key = new MnemonicKey({
mnemonic:
'beauty sniff protect ...',
});
const receiver = 'init10v3kg8hfvsj6tklfj5aam9ya5lmvtl9snqsawg';
const senderBalances = await lcd.bank.balance(key.accAddress);
const receiverBalances = await lcd.bank.balance(receiver);
console.log('sender balances:', senderBalances[0]);
// sender balances: Coins {
// _coins: {
// uinit: Coin { denom: 'uinit', amount: '99763592', isDecimal: false }
// }
// }
console.log('receiver balances:', receiverBalances[0]);
// receiver balances: Coins {
// _coins: {
// uinit: Coin { denom: 'uinit', amount: '100000', isDecimal: false }
// }
// }
}
checkBalances();Last updated