Skip to content

Commit d5d397f

Browse files
committed
Merge branch 'main' into feature/abstractAppNov
2 parents 7842b1d + 0d12e6f commit d5d397f

File tree

293 files changed

+5998
-2529
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

293 files changed

+5998
-2529
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ coverage
66
packages/**/build
77
packages/**/main
88
packages/**/module
9+
testgen

README.md

Lines changed: 177 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ The quickest and easiest way to interact with CosmWasm Contracts. `@cosmwasm/ts-
3636
- [React Query](#react-query)
3737
- [Recoil](#recoil)
3838
- [Message Composer](#message-composer)
39+
- [Message Builder](#message-builder)
40+
- [Use Contracts Hooks](#use-contracts-hooks)
3941
- [Bundles](#bundles)
4042
- [CLI Usage and Examples](#cli-usage-and-examples)
4143
- [Advanced Usage](#advanced-usage)
@@ -45,7 +47,7 @@ The quickest and easiest way to interact with CosmWasm Contracts. `@cosmwasm/ts-
4547
- [Exporting Schemas](#exporting-schemas)
4648
- [Developing](#developing)
4749
- [Related](#related)
48-
## Quickstart
50+
## Quickstart
4951

5052
Clone your project and `cd` into your contracts folder
5153

@@ -120,41 +122,44 @@ codegen({
120122
messageComposer: {
121123
enabled: false
122124
},
123-
msgBuilder: {
125+
messageBuilder: {
126+
enabled: false
127+
},
128+
useContractsHooks: {
124129
enabled: false
125130
}
126131
}
127132
}).then(() => {
128133
console.log('✨ all done!');
129134
});
130135
```
131-
#### Types
136+
#### Types
132137

133138
Typescript types and interfaces are generated in separate files so they can be imported into various generated plugins.
134139

135140
[see example output code](https://gist.github.com/pyramation/107d4e8e30dc5eb3ffc07bc3000f4dd0)
136141

137142
#### Types Options
138143

139-
| option | description |
140-
-------------------------| ----------------------------- | --------------------------------------------------- |
141-
| `types.enabled` | enable type generation |
142-
| `types.aliasExecuteMsg` | generate a type alias based on the contract name |
143-
| `types.aliasEntryPoints` | generate type aliases for the entry points based on the contract name |
144+
| option | description |
145+
| ------------------------ | ---------------------------------------------------- |
146+
| `types.enabled` | enable type generation |
147+
| `types.aliasExecuteMsg` | generate a type alias based on the contract name |
148+
| `types.aliasEntryPoints` | generate type aliases for the entry points based on the contract name |
144149

145150
### Client
146151

147-
The `client` plugin will generate TS client classes for your contracts. This option generates a `QueryClient` for queries as well as a `Client` for queries and mutations.
152+
The `client` plugin will generate TS client classes for your contracts. This option generates a `QueryClient` for queries as well as a `Client` for queries and mutations.
148153

149154
[see example output code](https://gist.github.com/pyramation/30508678b7563e286f06ccc5ac384817)
150155

151156
#### Client Options
152157

153-
| option | description |
154-
| --------------------------------------- | --------------------------------------------------- |
155-
| `client.enabled` | generate TS client classes for your contracts |
156-
| `client.execExtendsQuery` | execute should extend query message clients |
157-
| `client.noImplicitOverride` | should match your tsconfig noImplicitOverride option |
158+
| option | description |
159+
| --------------------------------------- | --------------------------------------------------- |
160+
| `client.enabled` | generate TS client classes for your contracts |
161+
| `client.execExtendsQuery` | execute should extend query message clients |
162+
| `client.noImplicitOverride` | should match your tsconfig noImplicitOverride option |
158163

159164
#### Client via CLI
160165

@@ -173,18 +178,18 @@ Generate [react-query v3](https://react-query-v3.tanstack.com/) or [react-query
173178

174179
#### React Query Options
175180

176-
| option | description |
177-
| ---------------------------- | ---------------------------------------------------------------------------- |
178-
| `reactQuery.enabled` | enable the react-query plugin |
179-
| `reactQuery.optionalClient` | allows contract client to be undefined as the component renders |
180-
| `reactQuery.queryKeys` | generates a const queryKeys object for use with invalidations and set values |
181-
| `reactQuery.queryFactory` | generates a const queryFactory object for useQueries and prefetchQueries use |
182-
| `reactQuery.version` | `v4` uses `@tanstack/react-query` and `v3` uses `react-query` |
183-
| `reactQuery.mutations` | also generate mutations |
184-
| `reactQuery.camelize` | use camelCase style for property names |
181+
| option | description |
182+
| --------------------------- | --------------------------------------------------------------------------- |
183+
| `reactQuery.enabled` | enable the react-query plugin |
184+
| `reactQuery.optionalClient` | allows contract client to be undefined as the component renders |
185+
| `reactQuery.queryKeys` | generates a const queryKeys object for use with invalidations and set values |
186+
| `reactQuery.queryFactory` | generates a const queryFactory object for useQueries and prefetchQueries use |
187+
| `reactQuery.version` | `v4` uses `@tanstack/react-query` and `v3` uses `react-query` |
188+
| `reactQuery.mutations` | also generate mutations |
189+
| `reactQuery.camelize` | use camelCase style for property names |
185190

186191

187-
#### React Query via CLI
192+
#### React Query via CLI
188193

189194
Here is an example without optional client, using v3 for `react-query`, without mutations:
190195

@@ -226,14 +231,14 @@ cosmwasm-ts-codegen generate \
226231
--plugin recoil \
227232
--schema ./schema \
228233
--out ./ts \
229-
--name MyContractName
234+
--name MyContractName
230235
```
231236

232237
#### Recoil Options
233238

234-
| option | description |
235-
| ------------------------------ | ------------------------------------------------------------------- |
236-
| `recoil.enabled` | enable the recoil plugin |
239+
| option | description |
240+
| ------------------------------ | ------------------------------------------------------------------- |
241+
| `recoil.enabled` | enable the recoil plugin |
237242

238243
### Message Composer
239244

@@ -248,34 +253,34 @@ cosmwasm-ts-codegen generate \
248253
--plugin message-composer \
249254
--schema ./schema \
250255
--out ./ts \
251-
--name MyContractName
256+
--name MyContractName
252257
```
253258
#### Message Composer Options
254259

255-
| option | description |
256-
| ------------------------------ | ------------------------------------------------------------------- |
257-
| `messageComposer.enabled` | enable the messageComposer plugin |
260+
| option | description |
261+
| ------------------------------ | ------------------------------------------------------------------- |
262+
| `messageComposer.enabled` | enable the messageComposer plugin |
258263

259-
### Msg Builder
264+
### Message Builder
260265

261-
Generate raw message jsons for use in your application with the `msg-builder` command.
266+
Generate raw message jsons for use in your application with the `message-builder` command.
262267

263268
[see example output code](https://gist.github.com/adairrr/b394e62beb9856b0351883f776650f26)
264269

265-
#### Msg Builder via CLI
270+
#### Message Builder via CLI
266271

267272
```sh
268273
cosmwasm-ts-codegen generate \
269-
--plugin msg-builder \
274+
--plugin message-builder \
270275
--schema ./schema \
271276
--out ./ts \
272-
--name MyContractName
277+
--name MyContractName
273278
```
274279
#### Message Builder Options
275280

276-
| option | description |
277-
-------------| ------------------------------ | ------------------------------------------------------------------- |
278-
| `msgBuilder.enabled` | enable the msgBuilder plugin |
281+
| option | description |
282+
|------------------------- | ---------------------------------- |
283+
| `messageBuilder.enabled` | enable the messageBuilder plugin |
279284

280285
### Abstract App
281286

@@ -298,6 +303,74 @@ cosmwasm-ts-codegen generate \
298303
| `abstractApp.enabled` | enable the abstractApp plugin |
299304
| `abstractApp.clientPrefix` | prefix the client name, defaults to `App` |
300305

306+
### Use Contracts Hooks
307+
308+
| option | description |
309+
| -------------------------------- | --------------------------------------- |
310+
| `useContractsHooks.enabled` | enable the `useContracts` plugin |
311+
312+
#### Use Contracts Provider Usage
313+
314+
```tsx
315+
import { useChain } from '@cosmos-kit/react';
316+
import { ContractsProvider } from '../path/to/codegen/contracts-context';
317+
318+
export default function YourComponent() {
319+
320+
const {
321+
address,
322+
getCosmWasmClient,
323+
getSigningCosmWasmClient
324+
} = useChain(chainName);
325+
326+
return (
327+
<ContractsProvider
328+
contractsConfig={{
329+
address,
330+
getCosmWasmClient,
331+
getSigningCosmWasmClient,
332+
}}
333+
>
334+
<SomeCoolComponent />
335+
</ContractsProvider>
336+
)
337+
};
338+
```
339+
340+
#### Use Contracts Provider Babel/TSC config
341+
342+
If you're using Babel, please make sure include `'@babel/preset-react'` in devDeps and presets in `.babelrc.js`:
343+
344+
```js
345+
presets: [
346+
'@babel/typescript',
347+
'@babel/env',
348+
'@babel/preset-react',
349+
]
350+
```
351+
352+
For `tsc`, you should set the `jsx` option to `'react'` in your `tsconfig.json`.
353+
354+
#### Use Contracts Hooks Usage
355+
356+
Once enabled, you can get contracts very simply:
357+
358+
```ts
359+
const { marketplace } = useContracts();
360+
```
361+
362+
```ts
363+
const marketplaceClient = marketplace.signingClient(marketplaceContract);
364+
await marketplaceClient.updateAskPrice({
365+
collection: token.collectionAddr,
366+
price: {
367+
amount,
368+
denom,
369+
},
370+
tokenId,
371+
});
372+
```
373+
301374
### Bundles
302375

303376
The bundler will make a nice package of all your contracts. For example:
@@ -312,17 +385,70 @@ const { CwAdminFactoryClient } = contracts.CwAdminFactory;
312385
```
313386
#### Bundler Options
314387

315-
| option | description |
316-
| --------------------- | -------------------------------------------------------------------------------- |
317-
| `bundle.enabled` | enable the bundler plugin |
318-
| `bundle.scope` | name of the scope, defaults to `contracts` (you can use `.` to make more scopes) |
319-
| `bundle.bundleFile` | name of the bundle file |
388+
| option | description |
389+
| --------------------- | -------------------------------------------------------------------------------- |
390+
| `bundle.enabled` | enable the bundler plugin |
391+
| `bundle.scope` | name of the scope, defaults to `contracts` (you can use `.` to make more scopes) |
392+
| `bundle.bundleFile` | name of the bundle file |
393+
394+
#### Coding Style
395+
396+
| option | description | default |
397+
| --------------------- | ---------------------------------------------- |
398+
| `useShorthandCtor` | Enable using shorthand constructor. | true |
399+
400+
Using shorthand constructor (Might not be transpiled correctly with babel):
401+
402+
```ts
403+
constructor(
404+
protected address: string | undefined,
405+
protected cosmWasmClient: CosmWasmClient | undefined,
406+
protected signingCosmWasmClient: SigningCosmWasmClient | undefined,
407+
private TSign?: new (
408+
client: SigningCosmWasmClient,
409+
sender: string,
410+
contractAddress: string
411+
) => TSign,
412+
private TQuery?: new (
413+
client: CosmWasmClient,
414+
contractAddress: string
415+
) => TQuery,
416+
private TMsgComposer?: new (
417+
sender: string,
418+
contractAddress: string
419+
) => TMsgComposer
420+
) {}
421+
```
422+
423+
Without using shorthand constructor:
424+
425+
```ts
426+
address: string | undefined;
427+
...
428+
TMsgComposer?: new (
429+
sender: string,
430+
contractAddress: string
431+
) => TMsgComposer;
432+
433+
constructor(
434+
address: string | undefined,
435+
...
436+
TMsgComposer?: new (
437+
sender: string,
438+
contractAddress: string
439+
) => TMsgComposer
440+
) {
441+
this.address = address;
442+
...
443+
this.TMsgComposer = TMsgComposer;
444+
}
445+
```
320446

321447
### CLI Usage and Examples
322448

323449
#### Interactive prompt
324450

325-
The CLI is interactive, and if you don't specify an option, it will interactively prompt you.
451+
The CLI is interactive, and if you don't specify an option, it will interactively prompt you.
326452

327453
```sh
328454
cosmwasm-ts-codegen generate
@@ -405,12 +531,12 @@ cosmwasm-ts-codegen generate \
405531
for lower-level access, you can import the various plugins directly:
406532

407533
```ts
408-
import {
534+
import {
409535
generateTypes,
410536
generateClient,
411537
generateReactQuery,
412538
generateRecoil,
413-
generateMessageComposer,
539+
generateMessageComposer
414540
} from '@cosmwasm/ts-codegen';
415541
```
416542
### Example Output
@@ -435,7 +561,7 @@ https://gist.github.com/pyramation/a9520ccf131177b1841e02a97d7d3731
435561

436562
https://gist.github.com/pyramation/43320e8b952751a0bd5a77dbc5b601f4
437563

438-
- `cosmwasm-ts-codegen generate --plugin msg-builder`
564+
- `cosmwasm-ts-codegen generate --plugin message-builder`
439565

440566
https://gist.github.com/adairrr/b394e62beb9856b0351883f776650f26
441567

@@ -502,7 +628,7 @@ export_schema_with_title(
502628
### Initial setup
503629

504630
```
505-
yarn
631+
yarn
506632
yarn bootstrap
507633
```
508634

@@ -529,7 +655,7 @@ See the [docs](https://github.com/CosmWasm/ts-codegen/blob/main/packages/wasm-as
529655

530656
Checkout these related projects:
531657

532-
* [@osmonauts/telescope](https://github.com/osmosis-labs/telescope) a "babel for the Cosmos", Telescope is a TypeScript Transpiler for Cosmos Protobufs.
658+
* [@cosmology/telescope](https://github.com/cosmology-tech/telescope) a "babel for the Cosmos", Telescope is a TypeScript Transpiler for Cosmos Protobufs.
533659
* [chain-registry](https://github.com/cosmology-tech/chain-registry) an npm module for the official Cosmos chain-registry.
534660
* [cosmos-kit](https://github.com/cosmology-tech/cosmos-kit) A wallet connector for the Cosmos ⚛️
535661
* [create-cosmos-app](https://github.com/cosmology-tech/create-cosmos-app) set up a modern Cosmos app by running one command.

__fixtures__/issues/98/out/98.client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* This file was automatically generated by @abstract-money/ts-codegen@latest.
2+
* This file was automatically generated by @cosmwasm/ts-codegen@latest.
33
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
4-
* and run the @abstract-money/ts-codegen generate command to regenerate this file.
4+
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
55
*/
66

77
import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate";

0 commit comments

Comments
 (0)