Here we can see how to send a simple transaction of ckb.
import { ConnectionService, Environments, WalletService, Logger, FeeRate } from"../src";constckbUrl="http://localhost:8117/rpc";constindexerUrl="http://localhost:8117/indexer";constmnemonic="private pond zero popular fashion omit february obscure pattern city camp pistol";const receivingAddress = "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqflx85grt0mnny6qsqwfxwkkvud4x3gwqgq2d0su";
constamount=BigInt(513*10**8); // 513 CKBconstmain=async () => {try {constconnectionService=newConnectionService(ckbUrl, indexerUrl,Environments.Testnet);constwallet=newWalletService(connectionService, mnemonic);// No need to sync as sendTransactions syncs before building the transactionconsttxHash=awaitwallet.sendTransaction(amount, mnemonic, receivingAddress,FeeRate.NORMAL);Logger.info(txHash);// You can view newly generated transaction through wallet.getTransactions when the tx is committed// If you want to know transaction statusconsttransaction=awaitwallet.getTransactionFromHash(txHash);Logger.info(JSON.stringify(transaction,null,2)); } catch (error) {Logger.error(`${error.name}: ${error.message}`); }};main();
To view not committed transactions we have to use the getTransactionFromHash method. Once it is finally committed we can sync and view it in getTransactions.