NimiqClient

public class NimiqClient

Nimiq JSONRPC Client

  • id

    Number in the sequence for the next request.

    Declaration

    Swift

    public var id: Int
  • Client initialization from a Config structure using shared URLSession. When no parameter is given, it uses de default configuration in the server (http://:@127.0.0.1:8648).

    Declaration

    Swift

    public convenience init(config: Config? = nil)

    Parameters

    config

    Options used for the configuration.

  • Client initialization.

    Declaration

    Swift

    public init(scheme: String = "http", user: String = "", password: String = "", host: String = "127.0.0.1", port: Int = 8648)

    Parameters

    scheme

    Protocol squeme, "http" or "https".

    user

    Authorized user.

    password

    Password for the authorized user.

    host

    Host IP address.

    port

    Host port.

    session

    Used to make all requests. If ommited the shared URLSession is used.

  • Returns a list of addresses owned by client.

    Declaration

    Swift

    public func accounts() throws -> [Any]?

    Return Value

    Array of Accounts owned by the client.

  • Returns the height of most recent block.

    Declaration

    Swift

    public func blockNumber() throws -> Int?

    Return Value

    The current block height the client is on.

  • Returns information on the current consensus state.

    Declaration

    Swift

    public func consensus() throws -> ConsensusState?

    Return Value

    Consensus state. established is the value for a good state, other values indicate bad.

  • Returns the value of the constant.

    Declaration

    Swift

    public func constant(_ constant: String) throws -> Int?

    Parameters

    constant

    The class and name of the constant (format should be Class.CONSTANT).

    Return Value

    The value of the constant.

  • Overrides the value of a constant. It sets the constant to the given value. To reset the constant use resetConstant() instead.

    Declaration

    Swift

    public func setConstant(_ constant: String, to value: Int) throws -> Int?

    Parameters

    constant

    The class and name of the constant (format should be Class.CONSTANT).

    value

    The new value of the constant.

    Return Value

    The new value of the constant.

  • Creates a new account and stores its private key in the client store.

    Declaration

    Swift

    public func createAccount() throws -> Wallet?

    Return Value

    Information on the wallet that was created using the command.

  • Creates and signs a transaction without sending it. The transaction can then be send via sendRawTransaction() without accidentally replaying it.

    Declaration

    Swift

    public func createRawTransaction(from transaction: OutgoingTransaction) throws -> String?

    Parameters

    transaction

    The transaction object.

    Return Value

    Hex-encoded transaction.

  • Returns details for the account of given address.

    Declaration

    Swift

    public func getAccount(forAddress address: String) throws -> Any?

    Parameters

    address

    Address to get account details.

    Return Value

    Details about the account. Returns the default empty basic account for non-existing accounts.

  • Returns the balance of the account of given address.

    Declaration

    Swift

    public func getBalance(forAddress address: String) throws -> Int?

    Parameters

    address

    Address to check for balance.

    Return Value

    The current balance at the specified address (in smalest unit).

  • Returns information about a block by hash.

    Declaration

    Swift

    public func getBlock(forHash hash: String, withTransactions: Bool? = nil) throws -> Block?

    Parameters

    hash

    Hash of the block to gather information on.

    withTransactions

    If true it returns the full transaction objects, if false only the hashes of the transactions.

    Return Value

    A block object or nil when no block was found.

  • Returns information about a block by block number.

    Declaration

    Swift

    public func getBlock(atHeight height: Int, withTransactions: Bool? = nil) throws -> Block?

    Parameters

    height

    The height of the block to gather information on.

    withTransactions

    If true it returns the full transaction objects, if false only the hashes of the transactions.

    Return Value

    A block object or nil when no block was found.

  • Returns a template to build the next block for mining. This will consider pool instructions when connected to a pool. If address and extraData are provided the values are overriden.

    Declaration

    Swift

    public func getBlockTemplate(forAddress address: String? = nil, withExtraData extraData: String = "") throws -> BlockTemplate?

    Parameters

    address

    The address to use as a miner for this block. This overrides the address provided during startup or from the pool.

    extraData

    Hex-encoded value for the extra data field. This overrides the extra data provided during startup or from the pool.

    Return Value

    A block template object.

  • Returns the number of transactions in a block from a block matching the given block hash.

    Declaration

    Swift

    public func getBlockTransactionCount(forHash hash: String) throws -> Int?

    Parameters

    hash

    Hash of the block.

    Return Value

    Number of transactions in the block found, or nil, when no block was found.

  • Returns the number of transactions in a block matching the given block number.

    Declaration

    Swift

    public func getBlockTransactionCount(atHeight height: Int) throws -> Int?

    Parameters

    height

    Height of the block.

    Return Value

    Number of transactions in the block found, or nil, when no block was found.

  • Returns information about a transaction by block hash and transaction index position.

    Declaration

    Swift

    public func getTransactionInBlock(forHash hash: String, index: Int) throws -> Transaction?

    Parameters

    hash

    Hash of the block containing the transaction.

    index

    Index of the transaction in the block.

    Return Value

    A transaction object or nil when no transaction was found.

  • Returns information about a transaction by block number and transaction index position.

    Declaration

    Swift

    public func getTransactionInBlock(atHeight height: Int, index: Int) throws -> Transaction?

    Parameters

    height

    Height of the block containing the transaction.

    index

    Index of the transaction in the block.

    Return Value

    A transaction object or nil when no transaction was found.

  • Returns the information about a transaction requested by transaction hash.

    Declaration

    Swift

    public func getTransaction(forHash hash: String) throws -> Transaction?

    Parameters

    hash

    Hash of a transaction.

    Return Value

    A transaction object or nil when no transaction was found.

  • Returns the receipt of a transaction by transaction hash.

    Declaration

    Swift

    public func getTransactionReceipt(forHash hash: String) throws -> TransactionReceipt?

    Parameters

    hash

    Hash of a transaction.

    Return Value

    A transaction receipt object, or nil when no receipt was found.

  • Returns the latest transactions successfully performed by or for an address. Note that this information might change when blocks are rewinded on the local state due to forks.

    Declaration

    Swift

    public func getTransactions(forAddress address: String, numberOfTransactions: Int? = nil) throws -> [Transaction]?

    Parameters

    address

    Address of which transactions should be gathered.

    numberOfTransactions

    Number of transactions that shall be returned.

    Return Value

    Array of transactions linked to the requested address.

  • Returns instructions to mine the next block. This will consider pool instructions when connected to a pool.

    Declaration

    Swift

    public func getWork(forAddress address: String? = nil, withExtraData extraData: String = "") throws -> WorkInstructions?

    Parameters

    address

    The address to use as a miner for this block. This overrides the address provided during startup or from the pool.

    extraData

    Hex-encoded value for the extra data field. This overrides the extra data provided during startup or from the pool.

    Return Value

    Mining work instructions.

  • Returns the number of hashes per second that the node is mining with.

    Declaration

    Swift

    public func hashrate() throws -> Float?

    Return Value

    Number of hashes per second.

  • Sets the log level of the node.

    Declaration

    Swift

    public func setLog(tag: String, to level: LogLevel) throws -> Bool?

    Parameters

    tag

    Tag: If "*" the log level is set globally, otherwise the log level is applied only on this tag.

    level

    Minimum log level to display.

    Return Value

    true if the log level was changed, false otherwise.

  • Returns information on the current mempool situation. This will provide an overview of the number of transactions sorted into buckets based on their fee per byte (in smallest unit).

    Declaration

    Swift

    public func mempool() throws -> MempoolInfo?

    Return Value

    Mempool information.

  • Returns transactions that are currently in the mempool.

    Declaration

    Swift

    public func mempoolContent(withTransactions: Bool? = nil) throws -> [Any]?

    Parameters

    withTransactions

    If true includes full transactions, if false includes only transaction hashes.

    Return Value

    Array of transactions (either represented by the transaction hash or a transaction object).

  • Returns the miner address.

    Declaration

    Swift

    public func minerAddress() throws -> String?

    Return Value

    The miner address configured on the node.

  • Returns the number of CPU threads for the miner.

    Declaration

    Swift

    public func minerThreads() throws -> Int?

    Return Value

    The number of threads allocated for mining.

  • Sets the number of CPU threads for the miner.

    Declaration

    Swift

    public func setMinerThreads(to threads: Int) throws -> Int?

    Parameters

    threads

    The number of threads to allocate for mining.

    Return Value

    The new number of threads allocated for mining.

  • Returns the minimum fee per byte.

    Declaration

    Swift

    public func minFeePerByte() throws -> Int?

    Return Value

    The new minimum fee per byte.

  • Sets the minimum fee per byte.

    Declaration

    Swift

    public func setMinFeePerByte(to fee: Int) throws -> Int?

    Parameters

    fee

    The new minimum fee per byte.

    Return Value

    The new minimum fee per byte.

  • Returns true if client is actively mining new blocks.

    Declaration

    Swift

    public func isMining() throws -> Bool?

    Return Value

    true if the client is mining, otherwise false.

  • Sets the client mining state.

    Declaration

    Swift

    public func setMining(to state: Bool) throws -> Bool?

    Parameters

    state

    The state to be set.

    Return Value

    true if the client is mining, otherwise false.

  • Returns number of peers currently connected to the client.

    Declaration

    Swift

    public func peerCount() throws -> Int?

    Return Value

    Number of connected peers.

  • Returns list of peers known to the client.

    Declaration

    Swift

    public func peerList() throws -> [Peer]?

    Return Value

    The list of peers.

  • Returns the state of the peer.

    Declaration

    Swift

    public func peerState(forAddress address: String) throws -> Peer?

    Parameters

    address

    The address of the peer.

    Return Value

    The current state of the peer.

  • Sets the state of the peer.

    Declaration

    Swift

    public func setPeerState(forAddress address: String, to command: PeerStateCommand) throws -> Peer?

    Parameters

    address

    The address of the peer.

    command

    The command to send.

    Return Value

    The new state of the peer.

  • Returns the mining pool.

    Declaration

    Swift

    public func pool() throws -> String?

    Return Value

    The mining pool connection string, or nil if not enabled.

  • Sets the mining pool.

    Declaration

    Swift

    public func setPool(toAddress address: Any) throws -> String?

    Parameters

    address

    The mining pool connection string (url:port) or boolean to enable/disable pool mining.

    Return Value

    The new mining pool connection string, or nil if not enabled.

  • Returns the confirmed mining pool balance.

    Declaration

    Swift

    public func poolConfirmedBalance() throws -> Int?

    Return Value

    The confirmed mining pool balance (in smallest unit).

  • Returns the connection state to mining pool.

    Declaration

    Swift

    public func poolConnectionState() throws -> PoolConnectionState?

    Return Value

    The mining pool connection state.

  • Sends a signed message call transaction or a contract creation, if the data field contains code.

    Declaration

    Swift

    public func sendRawTransaction(_ transaction: String) throws -> String?

    Parameters

    transaction

    The hex encoded signed transaction

    Return Value

    The Hex-encoded transaction hash.

  • Creates new message call transaction or a contract creation, if the data field contains code.

    Declaration

    Swift

    public func sendTransaction(_ transaction: OutgoingTransaction) throws -> String?

    Parameters

    transaction

    The hex encoded signed transaction

    Return Value

    The Hex-encoded transaction hash.

  • Submits a block to the node. When the block is valid, the node will forward it to other nodes in the network.

    Declaration

    Swift

    @discardableResult
    public func submitBlock(_ block: String) throws -> String?

    Parameters

    block

    Hex-encoded full block (including header, interlink and body). When submitting work from getWork, remember to include the suffix.

    Return Value

    Always nil.

  • Returns an object with data about the sync status or false.

    Declaration

    Swift

    public func syncing() throws -> Any?

    Return Value

    An object with sync status data or false, when not syncing.

  • Deserializes hex-encoded transaction and returns a transaction object.

    Declaration

    Swift

    public func getRawTransactionInfo(from transaction: String) throws -> Transaction?

    Parameters

    transaction

    The hex encoded signed transaction.

    Return Value

    The transaction object.

  • Resets the constant to default value.

    Declaration

    Swift

    public func resetConstant(_ constant: String) throws -> Int?

    Parameters

    constant

    Name of the constant.

    Return Value

    The new value of the constant.