> For the complete documentation index, see [llms.txt](https://lunes-labs.gitbook.io/dao-lunes-labs-pt/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lunes-labs.gitbook.io/dao-lunes-labs-pt/developers/para-desenvolvedores/smart-contract-ink-4.x/frontend-development/hooks/contracts/usecallsubscription.md).

# useCallSubscription

A React hook for calling a contract message on each new block and decoding a successful response or receiving an error. This is similar to [useCall](https://use.ink/frontend/core/hooks/contracts/use-call), except that there is no `send()` function in the response. The contract message will automatically be called on each new block. See [useCall](https://use.ink/frontend/core/hooks/contracts/use-call) to learn about more shared features.

See [useink/utils helpers](https://use.ink/frontend/utils/pick) for compatible functions that work well with this hook.

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

```javascript
import { useCallSubscription } from 'useink'
import { pickDecoded } from 'useink/utils'
import metadata from 'contract/metadata.json'

const CONTRACT_ADDRESS = '...'

// We define a response type so that `get.result.value.decoded` is of type SuccessfulResponse
interface SuccessfulResponse {
  foo: 'bar'
}

export const CallGetOnNewBlocks: React.FC = () => {
  const contract = useContract(CONTRACT_ADDRESS, metadata, 'aleph') 
  const args = ['arg-1', 2]
  const get = useCallSubscription<SuccessfulResponse>(contract, 'get', args)

  return (
    <>
      <h2>Get the Result the hard way: {get.result?.ok ? get.result.value.decoded.foo : '--'}</h2>
      <h2>Or the easy way: {pickDecoded(get.result)?.foo || '--'}</h2>
    </>
  )
}
```

### Calling with a default caller address[​](https://use.ink/frontend/react/hooks/contracts/use-call-subscription#calling-with-a-default-caller-address) <a href="#calling-with-a-default-caller-address" id="calling-with-a-default-caller-address"></a>

You must first define a default caller in [configuration](https://use.ink/frontend/configuration#configprops), then call the contract with options:

```javascript
const args = ['blue pill'];
const callSub = useCallSubscription(contract, 'get', args, { defaultCaller: true });
```

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

```javascript
{
  isSubmitting: boolean;
  result?: {
    ok: true;
    value: {
      raw: ContractExecResult; 
      decoded: T; // The response is decoded using contract Metadata, and of type `T`
    } | {
      ok: false;
      // error is set if a contract panics or has a failed assert(), or some other pallet errors.
      error: DispatchError | undefined; 
    }
  }
}
```
