> For the complete documentation index, see [llms.txt](https://docs.tomo.inc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tomo.inc/tomo-sdk/tomo-enterprise-sdk/for-babylon/cosmos-provider.md).

# Cosmos Provider

## Using Cosmos wallet provider

Cosmos wallet provider api is as below:

```javascript
import { TomoCosmosInjected, WalletProvider } from from '@tomo-inc/tomo-wallet-provider';
import { AminoSignResponse, BroadcastMode, KeplrSignOptions, StdSignature, StdSignDoc } from '@keplr-wallet/types';
import { OfflineAminoSigner, OfflineDirectSigner } from '@keplr-wallet/types/src/cosmjs';
import { SigningStargateClient } from '@cosmjs/stargate';

export declare class CosmosProvider extends WalletProvider {
    provider: TomoCosmosInjected;
    offlineSigner?: OfflineAminoSigner & OfflineDirectSigner;
    clientPromise?: Promise<SigningStargateClient>;
    constructor(chains: any[], provider: TomoCosmosInjected);
    connectWallet(): Promise<this>;
    /**
     * get @cosmjs/stargate SigningStargateClient
     */
    getSigningStargateClient(): Promise<SigningStargateClient>;
    getBalance(searchDenom: string): Promise<bigint>;
    /**
     * Gets the bech32Address of the connected wallet.
     * @returns A promise that resolves to the address of the connected wallet.
     */
    getAddress(): Promise<string>;
    /**
     * get the chainId of the connected wallet
     */
    getNetwork(): Promise<string>;
    signAmino(signerAddress: string, signDoc: StdSignDoc, signOptions?: KeplrSignOptions): Promise<AminoSignResponse>;
    signArbitrary(signer: string, data: string | Uint8Array): Promise<StdSignature>;
    sendTx(tx: Uint8Array, mode: BroadcastMode): Promise<Uint8Array>;
    getOfflineSigner(): Promise<OfflineAminoSigner & OfflineDirectSigner>;
    getPublicKeyHex(): Promise<string>
}
```

And after connected to wallet, cosmos wallet provider could be used as follows:

```javascript
<TomoContextProvider
  chainTypes={['cosmos', 'bitcoin']} // can be removed, we support both by default
  cosmosChains={[
    {
      id: 2,
      name: 'Cosmos',
      type: 'cosmos',
      network: 'cosmoshub-4'
      backendUrls:{rpcUrl:"your rpc node url"}
    }
  ]}
  providerOptions={{  // optional, support customized window object context
    getWindow() {
      return window.parent
    }
  }}
  ...
>
  <ChildComponent />
</TomoContextProvider>

// after connected, providers could be used
export function ChildComponent(props: ChildProps) {
  const providers = useTomoProviders()

  const signCosmos = async (address: string, amount: string) => {
    const curChainId = providers.cosmosProvider.getChainId()
    const key = await providers.cosmosProvider.provider.getKey(curChainId)  

    // construct your signDoc
    ...
    
    const { signed, signature } = await providers.cosmosProvider.signAmino(
      key.bech32Address,
      signDoc
    )
  }

  return (
    <div>
      <TomoSocial />
    </div>
  )
}
```

## Using customized SigningStargateClient

<pre class="language-javascript"><code class="lang-javascript">const providers = useTomoProviders()

providers.cosmosProvider!.initSigningStargateClient(
    await SigningStargateClient.connectWithSigner(
        rpcUrl,
        providers.cosmosProvider!.offlineSigner!,
        options
<strong>    )
</strong>);
</code></pre>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.tomo.inc/tomo-sdk/tomo-enterprise-sdk/for-babylon/cosmos-provider.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
