CosmJS utilities
yarn add cosmjs-utils
To broadcast messages, you'll want to use either keplr or an OfflineSigner
from cosmjs
using mnemonics.
Likely you'll want to use the Amino, so unless you need proto, you should use this one:
import { getOfflineSignerAmino as getOfflineSigner } from 'cosmjs-utils';
import { getOfflineSignerProto as getOfflineSigner } from 'cosmjs-utils';
WARNING: NOT RECOMMENDED TO USE PLAIN-TEXT MNEMONICS. Please take care of your security and use best practices such as AES encryption and/or methods from 12factor applications.
import { chains } from 'chain-registry';
const mnemonic =
'unfold client turtle either pilot stock floor glow toward bullet car science';
const chain = chains.find(({ chain_name }) => chain_name === 'osmosis');
const signer = await getOfflineSigner({
mnemonic,
chain
});
Now that you have your client
, you can broadcast messages:
import { signAndBroadcast } from 'cosmjs-utils';
const res = await signAndBroadcast({
client, // SigningStargateClient
chainId: 'osmosis-1', // use 'osmo-test-4' for testnet
address,
msgs: [msg],
fee,
memo: ''
});