useDryRun

A hook for calling a transaction as a dry run - a transction without spending any gas. Dry runs are useful to test if a transaction will be successful and for querying the exact Weight amount a transaction will need to succeed. This hook is used under the hood in useTxarrow-up-right, so you should only use this if you wish to display Dry Run information to the user before triggering a transaction.

See useink/utils helpersarrow-up-right for compatible functions that work well with this hook.

import { useDryRun, useContract } from 'useink'
import { pickTxInfo } from 'useink/utils'

export const MyContractView: React.FC = () => {
  const contract = useContract('...address', metadata, 'zeitgeist')
  
  const get = useDryRun<boolean>(contract, 'get')

  return (
    <>
      <button onClick={() => get.send()}>
        {get.isSubmitting ? 'Send Dry Run' : 'Sending...'}
      </div>

      <h2>Get the fee the hard way: {get.result.ok ? get.result.value.partialFee : '--'}</h2>
      <h2>Or the easy way: {pickTxInfo(get.result)?.partialFee || '--'}</h2>
    </>
  )
}

Calling with a default caller addressarrow-up-right

You must first define a default caller in configurationarrow-up-right, then call the contract with options:

Return Valuearrow-up-right

Last updated