You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You must then create the necessary `vite.config.ts` file.
51
51
52
52
```typescript
53
53
import { nodeResolve } from '@rollup/plugin-node-resolve'
54
-
import { Buffer } from 'buffer'
54
+
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'
55
55
import { defineConfig } from 'vite'
56
56
57
57
export default defineConfig({
58
-
define: {
59
-
global: {
60
-
Buffer: Buffer
61
-
}
62
-
},
63
-
plugins: [nodeResolve()],
58
+
59
+
plugins: [nodeResolve()],
60
+
61
+
optimizeDeps: {
62
+
esbuildOptions: {
63
+
define: {
64
+
global: 'globalThis',
65
+
},
66
+
plugins: [
67
+
NodeGlobalsPolyfillPlugin({
68
+
buffer:true
69
+
}),
70
+
],
71
+
},
72
+
}
64
73
})
65
74
```
66
75
@@ -76,17 +85,21 @@ By default, the generated client exports a client class that includes all the Co
76
85
77
86
To instantiate the client you need to provide environment information (endpoints and chain prefix) and an optional wallet (implementing the CosmJS OfflineSigner interface).
78
87
79
-
For example, to connect to a local chain instance running under the Ignite CLI defaults, using Keplr as a wallet:
88
+
For example, to connect to a local chain instance running under the Ignite CLI defaults, using a CosmJS wallet:
80
89
81
90
```typescript
82
91
import { Client } from '<path-to-ts-client>';
92
+
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
93
+
94
+
const mnemonic = "surround miss nominee dream gap cross assault thank captain prosper drop duty group candy wealth weather scale put";
Normally, Keplr provides a wallet object implementing the OfflineSigner interface so you can simply replace the wallet argument in client instantiation with it like so:
237
+
238
+
239
+
```typescript
240
+
import { Client } from '<path-to-ts-client>';
241
+
242
+
const chainId = 'mychain-1'
243
+
const client = new Client({
244
+
apiURL: "http://localhost:1317",
245
+
rpcURL: "http://localhost:26657",
246
+
prefix: "cosmos"
247
+
},
248
+
window.keplr.getOfflineSigner(chainId)
249
+
);
250
+
```
251
+
252
+
The problem is that for a new Ignite CLI scaffolded chain, Keplr has no knowledge of it thus requiring an initial call to [`experimentalSuggestChain()`](https://docs.keplr.app/api/suggest-chain.html) method to add the chain information to the user's Keplr instance.
253
+
254
+
The generated client makes this easier by offering a `useKeplr()` method that autodiscovers the chain information and sets it up for you. Thus you can instantiate the client without a wallet and then call `useKeplr()` to enable transacting via Keplr like so:
255
+
256
+
```typescript
257
+
import { Client } from '<path-to-ts-client>';
258
+
259
+
const client = new Client({
260
+
apiURL: "http://localhost:1317",
261
+
rpcURL: "http://localhost:26657",
262
+
prefix: "cosmos"
263
+
}
264
+
);
265
+
await client.useKeplr();
266
+
```
267
+
268
+
`useKeplr()`optionally accepts an object argument that contains one or more of the same keys as the `ChainInfo` type argument of `experimentalSuggestChain()` allowing you to override the auto-discovered values.
269
+
270
+
For example, the default chain name and token precision (which are not recorded on-chain) are set to `<chainId> Network` and `0` while the ticker for the denom is set to the denom name in uppercase. If you wanted to override these, you could do something like:
0 commit comments