import { Apophis, Cosmos, DefaultCosmosMiddlewares, LocalSigner } from '@apophis-sdk/cosmos';
Apophis.use(...DefaultCosmosMiddlewares);
const mnemonic = '...';
const signer = LocalSigner.fromMnemonic(mnemonic);
const network = await Cosmos.getNetworkFromRegistry('neutrontestnet');
const tx = Cosmos.tx([
new Bank.Send({
fromAddress: signer.address,
toAddress: signer.address,
amount: [Cosmos.coin(1n, 'untrn')],
}),
]);
await tx.estimateGas(network, signer, true); // true stores the gas price in the tx object
await signer.sign(network, tx);
const result = await tx.broadcast(network);
// success does not indicate that the tx was actually successful, only that it hasn't been rejected
// prior to execution, e.g. if the user has insufficient funds to cover gas.
if (result.success) {
try {
await Cosmos.ws(network).expectTx(tx);
console.log('tx successful:', tx.hash);
} catch (error) {
console.error('tx failed:', error);
}
}