# useContract

This hook is the foundation for many other hooks in **useink**. It returns a `ChainContract<T>` type and will automatically set the RPC url for the chain you specify.

### Usage[​](https://use.ink/frontend/react/hooks/contracts/use-contract#usage) <a href="#usage" id="usage"></a>

```javascript
import { useContract } from 'useink'

const CONTRACT_ADDRESS = '..'
const ALEPH_CONTRACT_ADDRESS = '..'

export const MyContractView: React.FC = () => {
  // The default chain will be used if you omit chainId as the third argument
  // The default chain is the first item in the chain config for UseInkProvider
  const contract = useContract(CONTRACT_ADDRESS, metadata)
  const alephContract = useContract(ALEPH_CONTRACT_ADDRESS, metadata, 'aleph')

  // use with other hooks...
  // e.g. useCall, useCallSubscription, useTx, etc

  return null
}
```

### Return Value[​](https://use.ink/frontend/react/hooks/contracts/use-contract#return-value) <a href="#return-value" id="return-value"></a>

```javascript
{
  // A contract object that contains metadata, and an api client set with a specific RPC url
  contract: ChainContract<T>, 
  // A strongly typed chain name found in `useink/chains`
  chainId: ChainId,
} | undefined
```

<br>


---

# Agent Instructions: 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:

```
GET https://lunes-labs.gitbook.io/dao-lunes-labs-pt/developers/para-desenvolvedores/smart-contract-ink-4.x/frontend-development/hooks/contracts/usecontract.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
