juno-network 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +122 -1
- package/package.json +2 -2
package/README.md
CHANGED
@@ -130,6 +130,128 @@ const {
|
|
130
130
|
voteWeighted
|
131
131
|
} = cosmos.gov.v1beta1.MessageComposer.fromPartial;
|
132
132
|
```
|
133
|
+
## Connecting with Wallets and Signing Messages
|
134
|
+
|
135
|
+
⚡️ For web interfaces, we recommend using [cosmos-kit](https://github.com/cosmology-tech/cosmos-kit). Continue below to see how to manually construct signers and clients.
|
136
|
+
### Initializing the Stargate Client
|
137
|
+
|
138
|
+
Use `getSigningCosmosClient` to get your `SigningStargateClient`, with the proto/amino messages full-loaded. No need to manually add amino types, just require and initialize the client:
|
139
|
+
|
140
|
+
```js
|
141
|
+
import { getSigningCosmosClient } from 'juno-network';
|
142
|
+
|
143
|
+
const stargateClient = await getSigningCosmosClient({
|
144
|
+
rpcEndpoint,
|
145
|
+
signer // OfflineSigner
|
146
|
+
});
|
147
|
+
```
|
148
|
+
## Creating Signers
|
149
|
+
|
150
|
+
To broadcast messages, you'll want to use either [keplr](https://docs.keplr.app/api/cosmjs.html) or an `OfflineSigner` from `cosmjs` using mnemonics.
|
151
|
+
|
152
|
+
### Cosmos Kit
|
153
|
+
|
154
|
+
If you use react, for keplr, we recommend using [cosmos-kit](https://github.com/cosmology-tech/cosmos-kit/tree/main/packages/react#2-signing-clients)
|
155
|
+
|
156
|
+
### Amino Signer
|
157
|
+
|
158
|
+
Likely you'll want to use the Amino, so unless you need proto, you should use this one:
|
159
|
+
|
160
|
+
```js
|
161
|
+
import { getOfflineSignerAmino as getOfflineSigner } from 'cosmjs-utils';
|
162
|
+
```
|
163
|
+
### Proto Signer
|
164
|
+
|
165
|
+
```js
|
166
|
+
import { getOfflineSignerProto as getOfflineSigner } from 'cosmjs-utils';
|
167
|
+
```
|
168
|
+
|
169
|
+
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.
|
170
|
+
|
171
|
+
```js
|
172
|
+
import { chains } from 'chain-registry';
|
173
|
+
|
174
|
+
const mnemonic =
|
175
|
+
'unfold client turtle either pilot stock floor glow toward bullet car science';
|
176
|
+
const chain = chains.find(({ chain_name }) => chain_name === 'juno');
|
177
|
+
const signer = await getOfflineSigner({
|
178
|
+
mnemonic,
|
179
|
+
chain
|
180
|
+
});
|
181
|
+
```
|
182
|
+
### Broadcasting messages
|
183
|
+
|
184
|
+
Now that you have your `stargateClient`, you can broadcast messages:
|
185
|
+
|
186
|
+
```js
|
187
|
+
const { send } = cosmos.bank.v1beta1.MessageComposer.withTypeUrl;
|
188
|
+
|
189
|
+
const msg = send({
|
190
|
+
amount: [
|
191
|
+
{
|
192
|
+
denom: 'ujuno',
|
193
|
+
amount: '1000'
|
194
|
+
}
|
195
|
+
],
|
196
|
+
toAddress: address,
|
197
|
+
fromAddress: address
|
198
|
+
});
|
199
|
+
|
200
|
+
const fee: StdFee = {
|
201
|
+
amount: [
|
202
|
+
{
|
203
|
+
denom: 'ujuno',
|
204
|
+
amount: '864'
|
205
|
+
}
|
206
|
+
],
|
207
|
+
gas: '86364'
|
208
|
+
};
|
209
|
+
const response = await stargateClient.signAndBroadcast(address, [msg], fee);
|
210
|
+
```
|
211
|
+
|
212
|
+
### Advanced Usage
|
213
|
+
|
214
|
+
If you want to manually construct a stargate client
|
215
|
+
|
216
|
+
```js
|
217
|
+
import { OfflineSigner, GeneratedType, Registry } from "@cosmjs/proto-signing";
|
218
|
+
import { AminoTypes, SigningStargateClient } from "@cosmjs/stargate";
|
219
|
+
|
220
|
+
import {
|
221
|
+
cosmosAminoConverters,
|
222
|
+
cosmosProtoRegistry,
|
223
|
+
cosmwasmAminoConverters,
|
224
|
+
cosmwasmProtoRegistry,
|
225
|
+
ibcProtoRegistry,
|
226
|
+
ibcAminoConverters
|
227
|
+
} from 'juno-network';
|
228
|
+
|
229
|
+
const signer: OfflineSigner = /* create your signer (see above) */
|
230
|
+
const rpcEndpint = 'https://rpc.cosmos.directory/juno'; // or another URL
|
231
|
+
|
232
|
+
const protoRegistry: ReadonlyArray<[string, GeneratedType]> = [
|
233
|
+
...cosmosProtoRegistry,
|
234
|
+
...publicawesomeProtoRegistry,
|
235
|
+
...cosmwasmProtoRegistry,
|
236
|
+
...ibcProtoRegistry
|
237
|
+
];
|
238
|
+
|
239
|
+
const aminoConverters = {
|
240
|
+
...cosmosAminoConverters,
|
241
|
+
...publicawesomeAminoConverters,
|
242
|
+
...cosmwasmAminoConverters,
|
243
|
+
...ibcAminoConverters
|
244
|
+
};
|
245
|
+
|
246
|
+
const registry = new Registry(protoRegistry);
|
247
|
+
const aminoTypes = new AminoTypes(aminoConverters);
|
248
|
+
|
249
|
+
const stargateClient = await SigningStargateClient.connectWithSigner(rpcEndpoint, signer, {
|
250
|
+
registry,
|
251
|
+
aminoTypes
|
252
|
+
});
|
253
|
+
```
|
254
|
+
|
133
255
|
## Credits
|
134
256
|
|
135
257
|
🛠 Built by Cosmology — if you like our tools, please consider delegating to [our validator ⚛️](https://cosmology.tech/validator)
|
@@ -138,4 +260,3 @@ Code built with the help of these related projects:
|
|
138
260
|
|
139
261
|
* [@cosmwasm/ts-codegen](https://github.com/CosmWasm/ts-codegen) for generated CosmWasm contract Typescript classes
|
140
262
|
* [@osmonauts/telescope](https://github.com/osmosis-labs/telescope) a "babel for the Cosmos", Telescope is a TypeScript Transpiler for Cosmos Protobufs.
|
141
|
-
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "juno-network",
|
3
|
-
"version": "0.5.
|
3
|
+
"version": "0.5.2",
|
4
4
|
"description": "juno",
|
5
5
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
6
6
|
"homepage": "https://github.com/CosmosContracts/typescript#readme",
|
@@ -86,5 +86,5 @@
|
|
86
86
|
"@osmonauts/lcd": "0.6.0",
|
87
87
|
"protobufjs": "^6.11.2"
|
88
88
|
},
|
89
|
-
"gitHead": "
|
89
|
+
"gitHead": "6bbfd7b29db2b4a5e92f8359e82085a4d91bcc01"
|
90
90
|
}
|