diff --git a/packages/cosmwasm-stargate/src/cosmwasmclient.ts b/packages/cosmwasm-stargate/src/cosmwasmclient.ts index aebe895c..c3c73c6a 100644 --- a/packages/cosmwasm-stargate/src/cosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/cosmwasmclient.ts @@ -24,6 +24,7 @@ import { import { HttpEndpoint, Tendermint34Client, + Tendermint37Client, TendermintClient, toRfc3339WithNanoseconds, } from "@cosmjs/tendermint-rpc"; @@ -95,11 +96,22 @@ export class CosmWasmClient { /** * Creates an instance by connecting to the given Tendermint RPC endpoint. * - * For now this uses the Tendermint 0.34 client. If you need Tendermint 0.37 - * support, see `create`. + * This uses auto-detection to decide between a Tendermint 0.37 and 0.34 client. + * To set the Tendermint client explicitly, use `create`. */ public static async connect(endpoint: string | HttpEndpoint): Promise { - const tmClient = await Tendermint34Client.connect(endpoint); + // Tendermint/CometBFT 0.34/0.37 auto-detection. Starting with 0.37 we seem to get reliable versions again 🎉 + // Using 0.34 as the fallback. + let tmClient: TendermintClient; + const tm37Client = await Tendermint37Client.connect(endpoint); + const version = (await tm37Client.status()).nodeInfo.version; + if (version.startsWith("0.37.")) { + tmClient = tm37Client; + } else { + tm37Client.disconnect(); + tmClient = await Tendermint34Client.connect(endpoint); + } + return CosmWasmClient.create(tmClient); } diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts index 03f6fe2f..031107e2 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts @@ -31,7 +31,12 @@ import { SignerData, StdFee, } from "@cosmjs/stargate"; -import { HttpEndpoint, Tendermint34Client, TendermintClient } from "@cosmjs/tendermint-rpc"; +import { + HttpEndpoint, + Tendermint34Client, + Tendermint37Client, + TendermintClient, +} from "@cosmjs/tendermint-rpc"; import { assert, assertDefined } from "@cosmjs/utils"; import { MsgWithdrawDelegatorReward } from "cosmjs-types/cosmos/distribution/v1beta1/tx"; import { MsgDelegate, MsgUndelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx"; @@ -182,15 +187,26 @@ export class SigningCosmWasmClient extends CosmWasmClient { /** * Creates an instance by connecting to the given Tendermint RPC endpoint. * - * For now this uses the Tendermint 0.34 client. If you need Tendermint 0.37 - * support, see `createWithSigner`. + * This uses auto-detection to decide between a Tendermint 0.37 and 0.34 client. + * To set the Tendermint client explicitly, use `createWithSigner`. */ public static async connectWithSigner( endpoint: string | HttpEndpoint, signer: OfflineSigner, options: SigningCosmWasmClientOptions = {}, ): Promise { - const tmClient = await Tendermint34Client.connect(endpoint); + // Tendermint/CometBFT 0.34/0.37 auto-detection. Starting with 0.37 we seem to get reliable versions again 🎉 + // Using 0.34 as the fallback. + let tmClient: TendermintClient; + const tm37Client = await Tendermint37Client.connect(endpoint); + const version = (await tm37Client.status()).nodeInfo.version; + if (version.startsWith("0.37.")) { + tmClient = tm37Client; + } else { + tm37Client.disconnect(); + tmClient = await Tendermint34Client.connect(endpoint); + } + return SigningCosmWasmClient.createWithSigner(tmClient, signer, options); } diff --git a/packages/stargate/src/signingstargateclient.ts b/packages/stargate/src/signingstargateclient.ts index ee4c2715..1216e0eb 100644 --- a/packages/stargate/src/signingstargateclient.ts +++ b/packages/stargate/src/signingstargateclient.ts @@ -118,8 +118,8 @@ export class SigningStargateClient extends StargateClient { /** * Creates an instance by connecting to the given Tendermint RPC endpoint. * - * For now this uses the Tendermint 0.34 client. If you need Tendermint 0.37 - * support, see `createWithSigner`. + * This uses auto-detection to decide between a Tendermint 0.37 and 0.34 client. + * To set the Tendermint client explicitly, use `createWithSigner`. */ public static async connectWithSigner( endpoint: string | HttpEndpoint, diff --git a/packages/stargate/src/stargateclient.ts b/packages/stargate/src/stargateclient.ts index 43d92a25..7f437573 100644 --- a/packages/stargate/src/stargateclient.ts +++ b/packages/stargate/src/stargateclient.ts @@ -193,8 +193,8 @@ export class StargateClient { /** * Creates an instance by connecting to the given Tendermint RPC endpoint. * - * For now this uses the Tendermint 0.34 client. If you need Tendermint 0.37 - * support, see `create`. + * This uses auto-detection to decide between a Tendermint 0.37 and 0.34 client. + * To set the Tendermint client explicitly, use `create`. */ public static async connect( endpoint: string | HttpEndpoint,