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 , so you should only use this if you wish to display Dry Run information to the user before triggering a transaction.
See for compatible functions that work well with this hook.
Usage
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>
</>
)
}
interface DryRun<T> {
send: Send<T>;
isSubmitting: boolean;
result?: DryRunResult<T>;
resolved: Boolean;
resetState: () => void; // A convenience function to reset result state
}
Calling with a default caller address
You must first define a default caller in , then call the contract with options: