useTxPaymentInfo

A hook for getting the partial fee and weight for a transaction before signing and sending. See useink/utils helpers for compatible functions that work well with this hook.

Usage

import { useTxPaymentInfo } from 'useink'

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

  return (
    <button onClick={get.send} disabled={get.isSubmitting}>
      {get.result?.paritalFee ? (
          `Gas price: ${get.result?.paritialFee.toString()}`
        ) : '--'}
    </button>
  )
}

Calling with a default caller address

You must first define a default caller in configuration, then call the contract with options:

const paymentInfo = useTxPaymentInfo(cRococoContract, 'flip');
const args = [];

paymentInfo.send(args, { defaultCaller: true });

Return Value

interface DispatchInfo {
  readonly weight: Weight; 
  readonly partialFee: Balance;
}

// useTxPaymentInfo retun type
interface PaymentInfoResult {
  isSubmitting: boolean;
  result?: DispatchInfo;
  send: (
    options?: ContractOptions,
    params?: unknown[],
    signerOptions?: Partial<SignerOptions>,
  ) => Promise<DispatchInfo | undefined>;
  resolved: boolean;
}

Last updated

Was this helpful?