🇵🇹
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
  • pickDecoded​
  • pickError​
  • pickDecodedError​
  • pickResultOk​
  • pickResultErr​
  • pickCallInfo​
  • pickTxInfo​

Was this helpful?

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

Pick Helpers

Last updated 1 year ago

Was this helpful?

Utility functions to easily "pick" deeply nested values or undefined

pickDecoded

pickDecoded picks a decoded value or undefined from DecodedContractResult returned by , and similar hooks.

const get = useCall<number>(flipper, 'get')

pickDecoded(get) // returns number or `undefined`

pickError

pickError picks a DispatchError (thrown in one of many possible pallets) or undefined from DecodedContractResult returned by , and similar hooks.

const get = useCall<number>(flipper, 'get')

pickError(get) // returns a Dispatch Error or `undefined`

pickDecodedError

pickDecodedError picks a DispatchError (thrown in one of many possible pallets) or undefined from DecodedContractResult and returns a string error message. This is a wrapper around .

const get = useCall<number>(flipper, 'get')

const errMessage = pickDecodedError(
  get,
  flipper, 
  { ContractTrapped: 'This is a custom message. There was a panic in the contract!' }, 
  'Something went wrong... This is a default error message',
);

console.error(errMessage); // string or undefined

// export function pickDecodedError( // call: CallResult | undefined, // contract: Contract, // moduleMessages?: Record<RegistryErrorMethod, string>, // defaultMessage?: string, // ): string | undefined {

interface SuccessStructInContract {
  Cool: string;
}

interface SomeErrorEnumInContract {
  NotCool: string;
}

interface Response = { Ok?: SuccessStructInContract, Err?: SomeErrorEnumInContract }

const get = useCall<Response>(flipper, 'get')

pickResultOk(get)?.Cool // returns a SuccessStructInContract object or `undefined`
interface SuccessStructInContract {
  Cool: string;
}

interface SomeErrorEnumInContract {
  NotCool: string;
}

interface Response = { Ok?: SuccessStructInContract, Err?: SomeErrorEnumInContract }

const get = useCall<Response>(flipper, 'get')

pickResultErr(get)?.NotCool // returns a SomeErrorEnumInContract object or `undefined`
const get = useCall(flipper, 'get')

pickCallInfo(get.result)

// Returns undefined or CallInfo
interface CallInfo {
  gasRequired: Weight;
  gasConsumed: Weight;
  storageDeposit: StorageDeposit;
}
const flip = useTx(flipper, 'flip')

pickTxInfo(flip.result)

// Returns undefined or Info
interface TxInfo {
  gasRequired: Weight;
  gasConsumed: Weight;
  storageDeposit: StorageDeposit;
  partialFee: Balance;
}

pickResultOk

pickResultOk picks the decoded Ok value or undefined if a contract returns a Result<T, E>. Can be used with and similar hooks.

pickResultErr

pickResultErr picks the decoded Err value or undefined if a contract returns a Result<T, E>. Can be used with and similar hooks.

pickCallInfo

pickCallInfo picks the CallInfo or undefined from a message result. Can be used with and similar hooks.

pickTxInfo

pickTxInfo picks the TxInfo or undefined from a tx or dry run result. Can be used with , , and similar hooks.

🖥️
📑
👾
​
useCall
​
useCall
​
decodeError
​
useCall
​
useCall
​
useCall
​
useTx
useDryRun