https://github.com/hyperweb-io/cosmjs-utils
cosmjs utilities
https://github.com/hyperweb-io/cosmjs-utils
Last synced: 11 days ago
JSON representation
cosmjs utilities
- Host: GitHub
- URL: https://github.com/hyperweb-io/cosmjs-utils
- Owner: hyperweb-io
- License: apache-2.0
- Created: 2022-08-04T05:49:18.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-09-27T22:41:06.000Z (over 3 years ago)
- Last Synced: 2025-10-06T18:01:39.599Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 1.31 MB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-Apache
Awesome Lists containing this project
README
# cosmjs-utils
CosmJS utilities
```
yarn add cosmjs-utils
```
## Creating Signers
To broadcast messages, you'll want to use either [keplr](https://docs.keplr.app/api/cosmjs.html) or an `OfflineSigner` from `cosmjs` using mnemonics.
### Amino Signer
Likely you'll want to use the Amino, so unless you need proto, you should use this one:
```js
import { getOfflineSignerAmino as getOfflineSigner } from 'cosmjs-utils';
```
### Proto Signer
```js
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.
```js
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
});
```
## Broadcasting messages
Now that you have your `client`, you can broadcast messages:
```js
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: ''
});
```