Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ coverage
packages/**/build
packages/**/main
packages/**/module
components/codegen
3 changes: 3 additions & 0 deletions examples/cosmwasm/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
38 changes: 38 additions & 0 deletions examples/cosmwasm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

# yarn
yarn.lock
97 changes: 97 additions & 0 deletions examples/cosmwasm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# CosmWasm TypeScript Codegen Example

This example demonstrates how to use CosmWasm Ts-Codegen TypeScript code generation with create-interchain-app. It showcases type-safe interactions with CosmWasm smart contracts using automatically generated TypeScript clients. The demo is mainly for baseCient functionality including query and execute, but you can add or modify to do the test for other clients.

## Features

- 🔗 **Wallet Integration**: Connect to Cosmos wallets using @interchain-kit
- 📝 **Type Safety**: Fully typed contract interactions using generated TypeScript clients
- ⚡ **Real-time Updates**: Live contract state queries and transaction execution

## Getting Started

### Prerequisites

- Node.js 18+ and npm/yarn
- A Cosmos wallet (Keplr recommended)
- Access to a Cosmos testnet (Stargaze testnet configured by default)

### Installation

1. Navigate to the example:
```bash
cd examples/cosmwasm
```

2. Install dependencies:
```bash
npm install
# or
yarn install
```

3. Start the development server:
```bash
npm run dev
# or
yarn dev
```

4. Open [http://localhost:3000](http://localhost:3000) in your browser

## Code Generation

The TypeScript clients in the `/codegen` directory are automatically generated from CosmWasm contract schemas using `@cosmwasm/ts-codegen`.

## Configuration

### Supported Chains

The example is configured to work with:
- **Osmosis Testnet** (default)
- **Stargaze**
- **Juno**

You can modify the chain configuration in `/config/chains.ts` to add support for additional networks.

### Wallet Support

Supported wallets include:
- **Keplr** (recommended)
- **Leap**
- **MetaMask** (for Ethereum-compatible chains)

Wallet configuration is managed in `/config/wallets.ts`.

## Development

### Adding New Contract Types

1. Add your contract schema to the project
2. Generate TypeScript clients using `@cosmwasm/ts-codegen`
3. Create React components for contract interactions
4. Add the components to the main page

## Troubleshooting

### Common Issues

1. **Wallet Connection Fails**
- Ensure Keplr or another supported wallet is installed
- Check that the wallet supports the selected chain
- Verify network configuration in wallet settings

2. **Contract Queries Fail**
- Verify the contract address is correct
- Ensure the contract exists on the selected network
- Check RPC endpoint connectivity

3. **Transaction Execution Fails**
- Verify sufficient balance for gas fees
- Check message format matches contract expectations
- Ensure proper permissions for contract execution

### Getting Help

- Check the [CosmWasm Ts-Codegen documentation](https://github.com/hyperweb-io/ts-codegen)
- View [Interchainjs documentation](https://github.com/hyperweb-io/interchainjs)
174 changes: 174 additions & 0 deletions examples/cosmwasm/codegen/Minter.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/**
* This file was automatically generated by @cosmwasm/ts-codegen@1.13.1.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
*/

import { ICosmWasmClient, ISigningCosmWasmClient } from "./baseClient";
import { StdFee } from "@interchainjs/types";
import { Addr, Timestamp, Uint64, Uint128, Config, Coin, ConfigResponse, ExecuteMsg, Decimal, InstantiateMsg, InstantiateMsg1, CollectionInfoForRoyaltyInfoResponse, RoyaltyInfoResponse, MintCountResponse, MintPriceResponse, MintableNumTokensResponse, QueryMsg, StartTimeResponse } from "./Minter.types";
export interface MinterReadOnlyInterface {
contractAddress: string;
config: () => Promise<ConfigResponse>;
mintableNumTokens: () => Promise<MintableNumTokensResponse>;
startTime: () => Promise<StartTimeResponse>;
mintPrice: () => Promise<MintPriceResponse>;
mintCount: ({
address
}: {
address: string;
}) => Promise<MintCountResponse>;
}
export class MinterQueryClient implements MinterReadOnlyInterface {
client: ICosmWasmClient;
contractAddress: string;
constructor(client: ICosmWasmClient, contractAddress: string) {
this.client = client;
this.contractAddress = contractAddress;
this.config = this.config.bind(this);
this.mintableNumTokens = this.mintableNumTokens.bind(this);
this.startTime = this.startTime.bind(this);
this.mintPrice = this.mintPrice.bind(this);
this.mintCount = this.mintCount.bind(this);
}
config = async (): Promise<ConfigResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
config: {}
});
};
mintableNumTokens = async (): Promise<MintableNumTokensResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
mintable_num_tokens: {}
});
};
startTime = async (): Promise<StartTimeResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
start_time: {}
});
};
mintPrice = async (): Promise<MintPriceResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
mint_price: {}
});
};
mintCount = async ({
address
}: {
address: string;
}): Promise<MintCountResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
mint_count: {
address
}
});
};
}
export interface MinterInterface extends MinterReadOnlyInterface {
contractAddress: string;
sender: string;
mint: (fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<any>;
setWhitelist: ({
whitelist
}: {
whitelist: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<any>;
updateStartTime: (fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<any>;
updatePerAddressLimit: ({
perAddressLimit
}: {
perAddressLimit: number;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<any>;
mintTo: ({
recipient
}: {
recipient: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<any>;
mintFor: ({
recipient,
tokenId
}: {
recipient: string;
tokenId: number;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<any>;
withdraw: (fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<any>;
}
export class MinterClient extends MinterQueryClient implements MinterInterface {
client: ISigningCosmWasmClient;
sender: string;
contractAddress: string;
constructor(client: ISigningCosmWasmClient, sender: string, contractAddress: string) {
super(client, contractAddress);
this.client = client;
this.sender = sender;
this.contractAddress = contractAddress;
this.mint = this.mint.bind(this);
this.setWhitelist = this.setWhitelist.bind(this);
this.updateStartTime = this.updateStartTime.bind(this);
this.updatePerAddressLimit = this.updatePerAddressLimit.bind(this);
this.mintTo = this.mintTo.bind(this);
this.mintFor = this.mintFor.bind(this);
this.withdraw = this.withdraw.bind(this);
}
mint = async (fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<any> => {
return await this.client.execute(this.sender, this.contractAddress, {
mint: {}
}, fee_, memo_, funds_);
};
setWhitelist = async ({
whitelist
}: {
whitelist: string;
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<any> => {
return await this.client.execute(this.sender, this.contractAddress, {
set_whitelist: {
whitelist
}
}, fee_, memo_, funds_);
};
updateStartTime = async (fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<any> => {
return await this.client.execute(this.sender, this.contractAddress, {
update_start_time: {}
}, fee_, memo_, funds_);
};
updatePerAddressLimit = async ({
perAddressLimit
}: {
perAddressLimit: number;
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<any> => {
return await this.client.execute(this.sender, this.contractAddress, {
update_per_address_limit: {
per_address_limit: perAddressLimit
}
}, fee_, memo_, funds_);
};
mintTo = async ({
recipient
}: {
recipient: string;
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<any> => {
return await this.client.execute(this.sender, this.contractAddress, {
mint_to: {
recipient
}
}, fee_, memo_, funds_);
};
mintFor = async ({
recipient,
tokenId
}: {
recipient: string;
tokenId: number;
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<any> => {
return await this.client.execute(this.sender, this.contractAddress, {
mint_for: {
recipient,
token_id: tokenId
}
}, fee_, memo_, funds_);
};
withdraw = async (fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<any> => {
return await this.client.execute(this.sender, this.contractAddress, {
withdraw: {}
}, fee_, memo_, funds_);
};
}
Loading
Loading