🇵🇹
DAO Lunes Labs - PT
  • 👋Seja Bem-vindo a DAO Lunes Labs
  • Overview
    • 🚪Introdução
    • 🚀Manifesto DAO Lunes Labs
    • 🍕Tokenomics
    • 👑Proposta de Valor
    • 🧑‍🚀Comunidade e Participação
    • 🗺️Roadmap
    • 💼Compromisso com Ética e Responsabilidade
    • 👾Programa de Bug Bounty: Lunes Security Initiative (LSI)
  • Developers
    • 💽Para Nodes
      • 🥾Instalar Node
        • 🏗️Rust toolchain
        • 🐧Linux
    • 🖥️Para Desenvolvedores
      • 📑Smart Contract Ink! 4.x
        • ✨Configuração
          • 📐Criando um projeto com ink!
          • 🖥️Compile Seu Contrato
          • ⛓️Executar um nó Lunes
          • ⬆️Implante seu contrato
          • 🔛Chame Seu Contrato
          • 🛠️Solução de problemas
        • 🪄Fundamentos
          • 👾Modelo de Contrato
          • 👨‍🚀Armazenando Valores
          • 🔭Lendo Valores do Armazenamento
          • 🦸‍♂️Alterando os Valores de Armazenamento
          • 🎡Eventos
          • 👨‍🔧Seletores
          • 🪶Definições de Trait
          • 🗣️Chamadas entre Contratos (Cross-Contract Calls)
          • 🦸Contratos Atualizáveis
          • 🤺Funções do Ambiente
          • 🏟️Tipos de Ambiente de Cadeia
          • 💠Metadados
          • 🧪Testes de Contrato
          • 🕵️‍♂️Depuração de Contratos
          • 🔬Verificação de Contrato
        • 🎙️Macros e Atributos
          • 📇#[ink::contract]
          • 👽#[ink(anonymous)]
          • 👷#[ink(constructor)]
          • 📏#[ink(default)]
          • 🎢#[ink(event)]
          • 🛩️#[ink(impl)]
          • 📧#[ink(message)]
          • 👨‍💼#[ink(namespace = "…")]
          • 💸#[ink(payable)]
          • ⚡#[ink(selector = S:u32)]
          • 💽#[ink(storage)]
          • 💣#[ink(topic)]
          • ⛓️#[ink::chain_extension]
        • 💽Storege & Data Structires
          • Working with Mapping
          • Storage Layout
          • Custom Data Structures
          • Metadata Format
        • 👾Frontend Development
          • Getting Started
          • Connect Wallet
          • Hooks
            • All Hooks
            • Contracts
              • useCall
              • useCallSubscription
              • useContract
              • useDryRun
              • useEventSubscription
              • useEvents
              • useTx
              • useTxPaymentInfo
            • Wallets
              • useWallet
              • useAllWallets
              • useInstalledWallets
              • useUninstalledWallets
            • API
              • useApi
              • useBalance
              • useBlockHeader
          • Configuration
          • useink / core
            • Contracts
              • Call
              • decodeCallResult
              • decodeError
              • getRegistryError
              • toAbiMessage
          • useink / chains
            • Getting Started
            • Chain Configurations
            • ChainId
          • useink / notifications
            • Getting Started
            • Configuration
            • useNotifications
            • toNotificationLevel
          • useink / utils
            • Getting Started
            • Pick Helpers
            • tx Helpers
            • Types
        • 💡Examples
          • 📔Smart Contracts
          • 📱Dapps
        • 🛠️Tools
          • 🖌️OpenBrush
      • 📒Smart Contract - EVM
        • Create ERC-20 Ink Token!
      • 💰Desenvolvendo uma Wallet Lunes
        • 👾Transações de Tokens PSP22
    • 🎨Para Designers
      • 🖌️Brand Lunes
Powered by GitBook
On this page
  • shouldDisable​
  • shouldDisableStrict​
  • hasAny​
  • isPendingSignature​
  • isNone​
  • isDryRun​
  • isErrored​
  • isFuture​
  • isReady​
  • isBroadcast​
  • isInBlock​
  • isInvalid​
  • isUsurped​
  • isDropped​
  • isFinalized​
  • isFinalityTimeout​
  • isRetracted​

Was this helpful?

  1. Developers
  2. Para Desenvolvedores
  3. Smart Contract Ink! 4.x
  4. Frontend Development
  5. useink / utils

tx Helpers

Last updated 1 year ago

Was this helpful?

There are a number of helper functions to check the status of a transaction. See for a full list of Transaction state values and descriptions.

shouldDisable

This function that returns true if a transaction state is DryRun, PendingSignature, or Broadcast. It is good practice to disable a button that triggers a transaction unless it has fully resolved. In a successful transaction, Broadcast state comes immediately before InBlock, which is when contracts emit events and the transaction is most likely to succeed. See shouldDisableStrict if you want to disable a button until it is Finalized, which may be more appropriate for high stake dApps.

import { shouldDisable } from 'useink';

export const Flipper = (contract) => {
    const flipTx = useTx(contract, 'flip');

    return (
        <button
            onClick={flipTx.signAndSend}
            disabled={shouldDisable(flipTx)}
        >
            {shouldDisable(flipTx) ? 'Flipping' : 'Flip!'}
        </button>
    )
}

shouldDisableStrict

This function that returns true if a transaction state is DryRun, PendingSignature, Broadcast, or InBlock. It is good practice to disable a button that triggers a transaction unless it has fully resolved.

import { shouldDisableStrict } from 'useink';

//... React code omitted
<button
    onClick={flipTx.signAndSend}
    disabled={shouldDisableStrict(flipTx)}
>
    {shouldDisableStrict(flipTx) ? 'Flipping' : 'Flip!'}
</button>

Returns a boolean if the transaction status has any of the arguments you pass in. Arguments must be of type Status;

import { hasAny } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(hasAny(['Broadcast', 'Finalized']));

Returns a boolean if the transaction status is PendingSignature. PendingSignature is set when you call signAndSend() on a transaction, which opens up a browser wallet extension modal for a user to sign. Once the transaction is signed the state will change to Broadcast.

import { isPendingSignature } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');
flipTx.signAndSend();

console.log(isPendingSignature(flipTx));

Returns a boolean if the transaction status is None.

import { isNone } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isNone(flipTx));

Returns true if the transaction status is DryRun. DryRun occurs immediately before a transaction is sent to verify if it will succeed.

import { isDryRun } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isDryRun(flipTx));

Returns a boolean if the transaction status is Errored, which means that there was an error in JavaScript somewhere.

import { isErrored } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isErrored(flipTx));

Returns a boolean if the transaction status is Future, which means that the transaction is moving in to the transaction pool.

import { isFuture } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isFuture(flipTx));

Returns a boolean if the transaction status is Ready, which means that the transaction is ready to be entered in to the transaction pool.

import { isReady } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isFuture(flipTx));

Returns a boolean if the transaction status is Broadcast. This is the point when events are emitted.

import { isBroadcast } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isBroadcast(flipTx));

Returns a boolean if the transaction status is InBlock. At this point it is very likely that the transaction will succeed. Most dApps can optimistically assume that the transaction is a success, but you may want to wait until Finalized stutus if you are building a high stakes dApp with monetary value so you can offer 100% guarantee that a transaction did succeed.

import { isInBlock } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isInBlock(flipTx));

Returns a boolean if the transaction status is Invalid.

import { isInvalid } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isInvalid(flipTx));

Returns a boolean if the transaction status is Usurped.

import { isUsurped } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isUsurped(flipTx));

Returns a boolean if the transaction status is Usurped.

import { isDropped } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isDropped(flipTx));

Returns a boolean if the transaction status is Finalized. This status guarantees that a transaction completed.

import { isFinalized } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isFinalized(flipTx));

Returns a boolean if the transaction status is FinalityTimeout.

import { isFinalityTimeout } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isFinalityTimeout(flipTx));

Returns a boolean if the transaction status is Retracted.

import { isRetracted } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isRetracted(flipTx));

hasAny

isPendingSignature

isNone

isDryRun

isErrored

isFuture

isReady

isBroadcast

isInBlock

isInvalid

isUsurped

isDropped

isFinalized

isFinalityTimeout

isRetracted

🖥️
📑
👾
useTx
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​