docs ⦿ dedot 🧑‍💻
DedotXTelegramGithub
typink ✏️
typink ✏️
  • Welcome to Typink
  • Introducing Typink
  • Getting started
    • Start a new dapp
    • Migrate from existing dapp
    • Supported networks
  • create-typink CLI
  • Hooks & Providers
    • TypinkProvider
    • useTypink
    • useContract
    • useContractQuery
    • useContractTx
    • useDeployer & useDeployerTx
    • useWatchContractEvent
    • useBalance & useBalances
    • usePSP22Balance
  • Utilities
    • formatBalance
    • txToaster
    • dedot/utils
  • HELP & FAQ
    • Tutorials
      • Develop ink! dApp using Typink
  • Telegram
  • Github
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Hooks & Providers

useContractQuery

Making a query to a registered contract. This hook manages the state of a contract query, including loading state, query results, and error handling. It automatically fetches data when the contract, function, or arguments change.

// ...
import { useContract, useContractQuery } from 'typink';
import { ContractId } from 'contracts/deployments';
import { GreeterContractApi } from 'contracts/types/greeter';

const { contract } = useContract<GreeterContractApi>(ContractId.GREETER);

const {
  data: greet,
  isLoading,
  refresh,
} = useContractQuery({
  contract,
  fn: 'greet',
});

// ...

Watch for changes

To automatically monitor updates in the contract storage, set the watch property to true.

// ...

const {
  data: greet,
  isLoading,
  refresh,
  watch: true
} = useContractQuery({
  contract,
  fn: 'greet',
});

// ...

PrevioususeContractNextuseContractTx

Last updated 3 months ago

Was this helpful?