Package org.iota

Class Client

    • Method Detail

      • destroyHandle

        public void destroyHandle()
        Destroys this client instance and drops its database connection. This client instance can no longer be used after.
        Overrides:
        destroyHandle in class NativeApi
      • getHealth

        public boolean getHealth​(java.lang.String nodeUrl)
                          throws ClientException
        Get the health of a given node.
        Parameters:
        nodeUrl - The URL of the node to check.
        Returns:
        True if the node is healthy, false otherwise.
        Throws:
        ClientException - on error.
      • postBlock

        public BlockId postBlock​(Block block)
                          throws ClientException
        Post a block to the node.
        Parameters:
        block - The block to be posted.
        Returns:
        The block id of the block that was posted.
        Throws:
        ClientException - on error.
      • postBlockRaw

        public BlockId postBlockRaw​(byte[] blockBytes)
                             throws ClientException
        Post a block to the node.
        Parameters:
        blockBytes - The raw bytes of the block to be posted.
        Returns:
        The block id of the block that was just posted.
        Throws:
        ClientException - on error.
      • getBlock

        public Block getBlock​(BlockId blockId)
                       throws ClientException
        Get a block by its block id
        Parameters:
        blockId - The block ID of the block you want to retrieve.
        Returns:
        A block object.
        Throws:
        ClientException - on error.
      • getBlockRaw

        public byte[] getBlockRaw​(BlockId blockId)
                           throws ClientException
        Get the raw bytes of a block
        Parameters:
        blockId - The block ID of the block you want to get.
        Returns:
        The raw bytes of the block.
        Throws:
        ClientException - on error.
      • getBlockMetadata

        public BlockMetadata getBlockMetadata​(BlockId blockId)
                                       throws ClientException
        Get the metadata of a block
        Parameters:
        blockId - The id of the block to get metadata for.
        Returns:
        BlockMetadata
        Throws:
        ClientException - on error.
      • getOutput

        public java.util.Map.Entry<Output,​OutputMetadata> getOutput​(OutputId outputId)
                                                                   throws ClientException
        Get the output with the given id
        Parameters:
        outputId - The id of the output you want to get.
        Returns:
        A map entry with the output and its metadata.
        Throws:
        ClientException - on error.
      • getOutputMetadata

        public OutputMetadata getOutputMetadata​(OutputId outputId)
                                         throws ClientException
        Get the metadata of an output
        Parameters:
        outputId - The output ID of the output you want to get metadata for.
        Returns:
        OutputMetadata
        Throws:
        ClientException - on error.
      • getReceiptsMigratedAt

        public Receipt[] getReceiptsMigratedAt​(int milestoneIndex)
                                        throws ClientException
        Returns the list of all the receipts that were migrated at the given milestone index
        Parameters:
        milestoneIndex - The index of the milestone to get the receipts for.
        Returns:
        Receipts
        Throws:
        ClientException - on error.
      • getIncludedBlock

        public Block getIncludedBlock​(TransactionId transactionId)
                               throws ClientException
        Returns the block that contains the transaction that was included in the ledger.
        Parameters:
        transactionId - The transaction that was included in the ledger.
        Returns:
        A block that contains the transaction.
        Throws:
        ClientException - on error.
      • getMilestoneById

        public MilestonePayload getMilestoneById​(MilestoneId milestoneId)
                                          throws ClientException
        Get the milestone payload for the given milestone id
        Parameters:
        milestoneId - The milestone ID of the milestone you want to get.
        Returns:
        A MilestonePayload object.
        Throws:
        ClientException - on error.
      • getMilestoneByIndex

        public MilestonePayload getMilestoneByIndex​(int milestoneIndex)
                                             throws ClientException
        Get the milestone at the specified index
        Parameters:
        milestoneIndex - The index of the milestone you want to retrieve.
        Returns:
        A MilestonePayload object.
        Throws:
        ClientException - on error.
      • getMilestoneByIdRaw

        public byte[] getMilestoneByIdRaw​(MilestoneId milestoneId)
                                   throws ClientException
        Returns the raw bytes of a milestone by its id
        Parameters:
        milestoneId - The milestone ID to get the raw data for.
        Returns:
        A byte array of the milestone data.
        Throws:
        ClientException - on error.
      • getMilestoneByIndexRaw

        public byte[] getMilestoneByIndexRaw​(int milestoneIndex)
                                      throws ClientException
        Returns the raw bytes of the milestone at the given index
        Parameters:
        milestoneIndex - The index of the milestone you want to retrieve.
        Returns:
        The raw bytes of the milestone at the given index.
        Throws:
        ClientException - on error.
      • getUtxoChangesById

        public UtxoChangesResponse getUtxoChangesById​(MilestoneId milestoneId)
                                               throws ClientException
        Returns the UTXO changes for the given milestone id
        Parameters:
        milestoneId - The milestone id of the milestone to get the UTXO changes for.
        Returns:
        The UTXO changes for the given milestone index.
        Throws:
        ClientException - on error.
      • getUtxoChangesByIndex

        public UtxoChangesResponse getUtxoChangesByIndex​(int milestoneIndex)
                                                  throws ClientException
        Returns the UTXO changes for the given milestone index
        Parameters:
        milestoneIndex - The index of the milestone to get the UTXO changes for.
        Returns:
        The UTXO changes for the given milestone index.
        Throws:
        ClientException - on error.
      • getPeers

        public Peer[] getPeers()
                        throws ClientException
        Get the list of peers connected to the node
        Returns:
        An array of Peer objects.
        Throws:
        ClientException - on error.
      • getBasicOutputIds

        public OutputId[] getBasicOutputIds​(NodeIndexerApi.QueryParams params)
                                     throws ClientException
        Returns the basic output ids that match the given query parameters
        Parameters:
        params - a QueryParams object that contains the following fields:
        Returns:
        An array of OutputIds.
        Throws:
        ClientException - on error.
      • getAliasOutputIds

        public OutputId[] getAliasOutputIds​(NodeIndexerApi.QueryParams params)
                                     throws ClientException
        Returns the alias output ids that match the given query parameters
        Parameters:
        params - a QueryParams object that contains the following fields:
        Returns:
        An array of OutputIds.
        Throws:
        ClientException - on error.
      • getNftOutputIds

        public OutputId[] getNftOutputIds​(NodeIndexerApi.QueryParams params)
                                   throws ClientException
        Returns the NFT output ids that match the given query parameters
        Parameters:
        params - a QueryParams object that contains the following fields:
        Returns:
        An array of OutputIds.
        Throws:
        ClientException - on error.
      • getFoundryOutputIds

        public OutputId[] getFoundryOutputIds​(NodeIndexerApi.QueryParams params)
                                       throws ClientException
        Returns the Foundry output ids that match the given query parameters
        Parameters:
        params - a QueryParams object that contains the following fields:
        Returns:
        An array of OutputIds.
        Throws:
        ClientException - on error.
      • getAliasOutputIdByAliasId

        public OutputId getAliasOutputIdByAliasId​(AliasId aliasId)
                                           throws ClientException
        The aliasId of the alias you want to get the outputId for.eturns the output id of an alias by its alias id
        Parameters:
        aliasId - The aliasId of the alias you want to get the outputId for.
        Returns:
        OutputId
        Throws:
        ClientException - on error.
      • getNftOutputIdByNftId

        public OutputId getNftOutputIdByNftId​(NftId nftId)
                                       throws ClientException
        The aliasId of the alias you want to get the outputId for.
        Parameters:
        nftId - The NFT Id of the NFT you want to get the outputId for.
        Returns:
        OutputId
        Throws:
        ClientException - on error.
      • getFoundryOutputIdByFoundryId

        public OutputId getFoundryOutputIdByFoundryId​(FoundryId foundryId)
                                               throws ClientException
        The aliasId of the alias you want to get the outputId for.
        Parameters:
        foundryId - The id of the foundry you want to get the output id for.
        Returns:
        The output id of the foundry.
        Throws:
        ClientException - on error.
      • getOutputs

        public java.util.List<java.util.Map.Entry<Output,​OutputMetadata>> getOutputs​(OutputId[] outputIds)
                                                                                    throws ClientException
        Get the outputs for the given output IDs
        Parameters:
        outputIds - An array of OutputId objects.
        Returns:
        A list of entries, where each entry is a pair of an Output and its OutputMetadata.
        Throws:
        ClientException - on error.
      • tryGetOutputs

        public java.util.List<java.util.Map.Entry<Output,​OutputMetadata>> tryGetOutputs​(OutputId[] outputIds)
                                                                                       throws ClientException
        Try get the outputs for the given output IDs
        Parameters:
        outputIds - An array of OutputId objects.
        Returns:
        A list of entries, where each entry is a pair of an output and its metadata.
        Throws:
        ClientException - on error.
      • findBlocks

        public Block[] findBlocks​(BlockId[] blockIds)
                           throws ClientException
        Finds blocks by their ids
        Parameters:
        blockIds - An array of BlockId objects.
        Returns:
        An array of blocks.
        Throws:
        ClientException - on error.
      • retry

        public java.util.Map.Entry<BlockId,​Block> retry​(BlockId blockId)
                                                       throws ClientException
        Retry a block that has failed to process
        Parameters:
        blockId - The id of the block to retry.
        Returns:
        A map entry with the block id and the block.
        Throws:
        ClientException - on error.
      • retryUntilIncluded

        public java.util.LinkedHashMap<BlockId,​Block> retryUntilIncluded​(BlockId blockId,
                                                                               int interval,
                                                                               int maxAttempts)
                                                                        throws ClientException
        Retry until the block is included in the blockchain
        Parameters:
        blockId - The block ID to retry.
        interval - The interval in seconds between each attempt to retrieve the block.
        maxAttempts - The maximum number of attempts to make before giving up.
        Returns:
        A LinkedHashMap of BlockId and Block.
        Throws:
        ClientException - on error.
      • consolidateFunds

        public java.lang.String consolidateFunds​(SecretManager secretManager,
                                                 GenerateAddressesOptions generateAddressesOptions)
                                          throws ClientException
        This function will consolidate all funds of the wallet
        Parameters:
        secretManager - The secret manager that holds the secret for the account you want to consolidate funds for.
        generateAddressesOptions - This is an object that contains the following parameters:
        Returns:
        A String containing the transaction hash.
        Throws:
        ClientException - on error.
      • findInputs

        public UtxoInput[] findInputs​(java.lang.String[] addresses,
                                      int amount)
                               throws ClientException
        Finds the inputs that are needed to create a transaction with the given amount
        Parameters:
        addresses - An array of addresses to search for inputs.
        amount - The amount you want to spend.
        Returns:
        An array of UtxoInput objects.
        Throws:
        ClientException - on error.
      • findOutputs

        public java.util.List<java.util.Map.Entry<Output,​OutputMetadata>> findOutputs​(OutputId[] outputIds,
                                                                                            java.lang.String[] addresses)
                                                                                     throws ClientException
        Finds outputs by their ids and addresses
        Parameters:
        outputIds - An array of OutputId objects.
        addresses - The addresses to search for outputs.
        Returns:
        A list of outputs and their metadata.
        Throws:
        ClientException - on error.
      • reattach

        public java.util.Map.Entry<BlockId,​Block> reattach​(BlockId blockId)
                                                          throws ClientException
        Reattaches a block to the blockchain
        Parameters:
        blockId - The id of the block to reattach.
        Returns:
        A map entry with the block id and the block.
        Throws:
        ClientException - on error.
      • reattachUnchecked

        public java.util.Map.Entry<BlockId,​Block> reattachUnchecked​(BlockId blockId)
                                                                   throws ClientException
        ReattachUnchecked() reattaches a block to the tangle, without checking if it's necessary to.
        Parameters:
        blockId - The block id of the block to reattach.
        Returns:
        A map entry with the block id and the block.
        Throws:
        ClientException - on error.
      • promote

        public java.util.Map.Entry<BlockId,​Block> promote​(BlockId blockId)
                                                         throws ClientException
        Promote a block
        Parameters:
        blockId - The id of the block to promote.
        Returns:
        A map entry with the block id and the block.
        Throws:
        ClientException - on error.
      • promoteUnchecked

        public java.util.Map.Entry<BlockId,​Block> promoteUnchecked​(BlockId blockId)
                                                                  throws ClientException
        Promote a block, without checking if it's necessary to.
        Parameters:
        blockId - The id of the block to promote.
        Returns:
        A map entry with the block id and the block.
        Throws:
        ClientException - on error.
      • bech32ToHex

        public java.lang.String bech32ToHex​(java.lang.String bech32)
                                     throws ClientException
        Converts a bech32 address to a hex address
        Parameters:
        bech32 - bech32 address
        Returns:
        A hex string.
        Throws:
        ClientException - on error.
      • hexToBech32

        public java.lang.String hexToBech32​(java.lang.String hex,
                                            java.lang.String bech32)
                                     throws ClientException
        Converts a hex string to a bech32 string
        Parameters:
        hex - The hexadecimal string to be converted.
        bech32 - The bech32 to use.
        Returns:
        The bech32 address.
        Throws:
        ClientException - on error.
      • aliasIdToBech32

        public java.lang.String aliasIdToBech32​(AliasId aliasId,
                                                java.lang.String bech32Hrp)
                                         throws ClientException
        Converts an alias id to a bech32 address.
        Parameters:
        aliasId - The alias id to be converted.
        bech32Hrp - The bech 32 human readable part to use.
        Returns:
        The bech32 address.
        Throws:
        ClientException - on error.
      • hexPublicKeyToBech32Address

        public java.lang.String hexPublicKeyToBech32Address​(java.lang.String hex,
                                                            java.lang.String bech32)
                                                     throws ClientException
        Converts a hex public key to a bech32 address
        Parameters:
        hex - The public key in hexadecimal format.
        bech32 - The bech32 prefix
        Returns:
        The bech32 address.
        Throws:
        ClientException - on error.
      • parseBech32Address

        public java.lang.String parseBech32Address​(java.lang.String address)
                                            throws ClientException
        This function is used to parse the Bech32 address
        Parameters:
        address - The address to be parsed.
        Returns:
        The address in hex format.
        Throws:
        ClientException - on error.
      • isAddressValid

        public boolean isAddressValid​(java.lang.String address)
                               throws ClientException
        Checks if the given address is valid
        Parameters:
        address - The address to validate.
        Returns:
        A boolean value.
        Throws:
        ClientException - on error.
      • generateMnemonic

        public java.lang.String generateMnemonic()
                                          throws ClientException
        Generate a mnemonic
        Returns:
        The mnemonic string.
        Throws:
        ClientException - on error.
      • mnemonicToHexSeed

        public java.lang.String mnemonicToHexSeed​(java.lang.String mnemonic)
                                           throws ClientException
        Converts a mnemonic to a hex seed
        Parameters:
        mnemonic - The mnemonic to convert to a hex seed.
        Returns:
        A hex seed.
        Throws:
        ClientException - on error.
      • getBlockId

        public BlockId getBlockId​(Block block)
                           throws ClientException
        This function computes the block id of a block
        Parameters:
        block - The block to compute the block id from.
        Returns:
        The block id of the block.
        Throws:
        ClientException - on error.
      • getTransactionId

        public TransactionId getTransactionId​(TransactionPayload payload)
                                       throws ClientException
        This function returns a transaction ID for a given transaction payload
        Parameters:
        payload - The payload of the transaction.
        Returns:
        A TransactionId object.
        Throws:
        ClientException - on error.
      • computeAliasId

        public AliasId computeAliasId​(OutputId aliasOutputId)
                               throws ClientException
        Computes the alias id for the given alias output id
        Parameters:
        aliasOutputId - The output ID of the alias.
        Returns:
        The alias id of the output id.
        Throws:
        ClientException - on error.
      • computeNftId

        public NftId computeNftId​(OutputId nftOutputId)
                           throws ClientException
        Computes the NFT ID from the NFT output ID
        Parameters:
        nftOutputId - The output id of the NFT.
        Returns:
        The NFT ID of the NFT output.
        Throws:
        ClientException - on error.
      • computeFoundryId

        public FoundryId computeFoundryId​(java.lang.String aliasAddress,
                                          int serialNumber,
                                          int tokenScheme)
                                   throws ClientException
        Computes the Foundry ID for a given alias address, serial number, and token scheme
        Parameters:
        aliasAddress - The alias address of the device.
        serialNumber - The serial number of the token.
        tokenScheme - The token scheme to use. This is a value from the TokenScheme enum.
        Returns:
        A FoundryId object.
        Throws:
        ClientException - on error.
      • generateAddresses

        public java.lang.String[] generateAddresses​(SecretManager secretManager,
                                                    GenerateAddressesOptions generateAddressesOptions)
                                             throws ClientException
        Generate addresses for a given secret manager
        Parameters:
        secretManager - The secret manager to use for generating the addresses.
        generateAddressesOptions - The options for generating addresses.
        Returns:
        A list of addresses
        Throws:
        ClientException - on error.
      • buildAndPostBlock

        public java.util.Map.Entry<BlockId,​Block> buildAndPostBlock​(SecretManager secretManager,
                                                                          BuildBlockOptions options)
                                                                   throws ClientException
        Builds a block and posts it to the network
        Parameters:
        secretManager - The secret manager to use for signing the block.
        options - The options for building the block.
        Returns:
        A map entry with the block id and the block itself.
        Throws:
        ClientException - on error.
      • getNetworkInfo

        public com.google.gson.JsonObject getNetworkInfo()
                                                  throws ClientException
        Get network information
        Returns:
        A JsonObject
        Throws:
        ClientException - on error.
      • getNetworkId

        public int getNetworkId()
                         throws ClientException
        Get the network ID of the current network
        Returns:
        The network ID of the current network.
        Throws:
        ClientException - on error.
      • getBech32Hrp

        public java.lang.String getBech32Hrp()
                                      throws ClientException
        Get the Bech32 HRP for the current network
        Returns:
        The Bech32 Human Readable Part (HRP) for addresses.
        Throws:
        ClientException - on error.
      • getMinPowScore

        public float getMinPowScore()
                             throws ClientException
        Get the minimum PoW score required for a transaction to be accepted
        Returns:
        The minimum PoW score.
        Throws:
        ClientException - on error.
      • getTipsInterval

        public int getTipsInterval()
                            throws ClientException
        Get the tips interval in seconds
        Returns:
        The interval in seconds.
        Throws:
        ClientException - on error.
      • getLocalPow

        public boolean getLocalPow()
                            throws ClientException
        Returns true if the local PoW is enabled, otherwise false.
        Returns:
        true if the local PoW is enabled, otherwise false.
        Throws:
        ClientException - on error.
      • getFallbackToLocalPow

        public boolean getFallbackToLocalPow()
                                      throws ClientException
        Returns true if the client is configured to fallback to local proof of work if the remote proof of work service is unavailable
        Returns:
        true if the client is configured to fallback to local proof of work, else returns false.
        Throws:
        ClientException - on error.
      • getUnhealthyNodes

        public Node[] getUnhealthyNodes()
                                 throws ClientException
        Get the list of nodes that are not healthy
        Returns:
        The array of nodes that are not healthy.
        Throws:
        ClientException - on error.
      • getLedgerNanoStatus

        public LedgerNanoStatus getLedgerNanoStatus​(boolean isSimulator)
                                             throws ClientException
        Get the status of the Ledger Nano device
        Parameters:
        isSimulator - true if you want to use the simulator, false if you want to use the real device.
        Returns:
        LedgerNanoStatus
        Throws:
        ClientException - on error.
      • prepareTransaction

        public PreparedTransactionData prepareTransaction​(SecretManager secretManager,
                                                          BuildBlockOptions buildBlockOptions)
                                                   throws ClientException
        Prepares a transaction for signing
        Parameters:
        secretManager - The secret manager that holds the secret for the account.
        buildBlockOptions - This is the object that contains the transaction details.
        Returns:
        The prepared transaction.
        Throws:
        ClientException - on error.
      • signTransaction

        public TransactionPayload signTransaction​(SecretManager secretManager,
                                                  PreparedTransactionData preparedTransactionData)
                                           throws ClientException
        Signs the given prepared transaction using the secret manager
        Parameters:
        secretManager - The secret manager that holds the secret key for the account that will sign the transaction.
        preparedTransactionData - The transaction data that was prepared by the prepareTransaction method.
        Returns:
        The signed transaction.
        Throws:
        ClientException - on error.
      • storeMnemonic

        public void storeMnemonic​(SecretManager secretManager,
                                  java.lang.String mnemonic)
                           throws ClientException
        Stores the mnemonic in the secret manager
        Parameters:
        secretManager - The secret manager to use.
        mnemonic - The mnemonic to store.
        Throws:
        ClientException - on error.
      • postBlockPayload

        public java.util.Map.Entry<BlockId,​Block> postBlockPayload​(BlockPayload payload)
                                                                  throws ClientException
        Automatically builds a block containing the given block payload and broadcasts it to the network.
        Parameters:
        payload - The payload to be posted.
        Returns:
        A map entry of the posted block id and the block.
        Throws:
        ClientException - on error.
      • getTokenSupply

        public java.lang.String getTokenSupply()
                                        throws ClientException
        Returns the token supply.
        Returns:
        The token supply.
        Throws:
        ClientException - on error.