- NimiqClient
- __construct
- getPeerCount
- getSyncingState
- getConsensusState
- getPeerList
- getPeer
- setPeerState
- sendRawTransaction
- createRawTransaction
- sendTransaction
- getRawTransactionInfo
- getTransactionByBlockHashAndIndex
- getTransactionByBlockNumberAndIndex
- getTransactionByHash
- getTransactionReceipt
- getTransactionsByAddress
- getMempoolContent
- getMempool
- getMinFeePerByte
- setMinFeePerByte
- getMiningState
- setMiningState
- getHashrate
- getMinerThreads
- setMinerThreads
- getMinerAddress
- getPool
- setPool
- getPoolConnectionState
- getPoolConfirmedBalance
- getWork
- getBlockTemplate
- submitBlock
- getAccounts
- createAccount
- getBalance
- getAccount
- getBlockNumber
- getBlockTransactionCountByHash
- getBlockTransactionCountByNumber
- getBlockByHash
- getBlockByNumber
- getConstant
- setConstant
- resetConstant
- setLogLevel
RPC Client to communicate with a Nimiq Node.
- Full name: \NimiqCommunity\RpcClient\NimiqClient
- Parent class:
Creates a new instance of the Nimiq client.
NimiqClient::__construct( array $config = array() ): \NimiqCommunity\RpcClient\NimiqClient
$config
array, all fields are optional:
$config = [
'scheme' => 'http',
'host' => '127.0.0.1',
'port' => 8648,
'user' => 'luna',
'password' => 'moon',
'timeout' => false,
];
Parameters:
Parameter | Type | Description |
---|---|---|
$config |
array | client config array (optional) |
Return Value:
new client instance
Returns number of peers currently connected to the client.
NimiqClient::getPeerCount( ): integer
Return Value:
number of connected peers
Returns an object with data about the sync status or false.
NimiqClient::getSyncingState( ): boolean|\NimiqCommunity\RpcClient\Models\SyncingStatus
Return Value:
object with sync status data or false, when not syncing
Returns information on the current consensus state.
NimiqClient::getConsensusState( ): string
Return Value:
string describing the consensus state. ConsensusState::Established is the value for a good state, other values indicate bad state.
Returns list of peers known to the client.
NimiqClient::getPeerList( ): array<mixed,\NimiqCommunity\RpcClient\Models\Peer>
Return Value:
list of peers
Returns the state of the peer.
NimiqClient::getPeer( string $peer ): \NimiqCommunity\RpcClient\Models\Peer
Parameters:
Parameter | Type | Description |
---|---|---|
$peer |
string | address of the peer |
Return Value:
current state of the peer
Sets the state of the peer.
NimiqClient::setPeerState( string $peer, string $command ): \NimiqCommunity\RpcClient\Models\Peer
Parameters:
Parameter | Type | Description |
---|---|---|
$peer |
string | address of the peer |
$command |
string | command to perform (one of PeerStateCommand::Connect, PeerStateCommand::Disconnect, PeerStateCommand::Ban, PeerStateCommand::Unban) |
Return Value:
new state of the peer
Sends a signed message call transaction or a contract creation, if the data field contains code.
NimiqClient::sendRawTransaction( string $txHex ): string
Parameters:
Parameter | Type | Description |
---|---|---|
$txHex |
string | hex-encoded signed transaction |
Return Value:
hex-encoded transaction hash
Creates and signs a transaction without sending it. The transaction can then be send via sendRawTransaction without accidentally replaying it.
NimiqClient::createRawTransaction( \NimiqCommunity\RpcClient\Models\OutgoingTransaction $tx ): string
Parameters:
Parameter | Type | Description |
---|---|---|
$tx |
\NimiqCommunity\RpcClient\Models\OutgoingTransaction | transaction object |
Return Value:
hex-encoded transaction
Creates new message call transaction or a contract creation, if the data field contains code.
NimiqClient::sendTransaction( \NimiqCommunity\RpcClient\Models\OutgoingTransaction $tx ): string
Parameters:
Parameter | Type | Description |
---|---|---|
$tx |
\NimiqCommunity\RpcClient\Models\OutgoingTransaction | transaction object |
Return Value:
hex-encoded transaction hash
Deserializes hex-encoded transaction and returns a transaction object.
NimiqClient::getRawTransactionInfo( string $txHex ): \NimiqCommunity\RpcClient\Models\Transaction
Parameters:
Parameter | Type | Description |
---|---|---|
$txHex |
string | hex-encoded transaction |
Return Value:
transaction object
Returns information about a transaction by block hash and transaction index position.
NimiqClient::getTransactionByBlockHashAndIndex( string $blockHash, integer $txIndex ): null|\NimiqCommunity\RpcClient\Models\Transaction
Parameters:
Parameter | Type | Description |
---|---|---|
$blockHash |
string | hash of the block containing the transaction |
$txIndex |
integer | index of the transaction in the block |
Return Value:
transaction object, or null when no transaction was found
Returns information about a transaction by block number and transaction index position.
NimiqClient::getTransactionByBlockNumberAndIndex( integer $blockNumber, integer $txIndex ): null|\NimiqCommunity\RpcClient\Models\Transaction
Parameters:
Parameter | Type | Description |
---|---|---|
$blockNumber |
integer | height of the block containing the transaction |
$txIndex |
integer | index of the transaction in the block |
Return Value:
transaction object, or null when no transaction was found
Returns the information about a transaction requested by transaction hash.
NimiqClient::getTransactionByHash( string $hash ): null|\NimiqCommunity\RpcClient\Models\Transaction
Parameters:
Parameter | Type | Description |
---|---|---|
$hash |
string | hash of the transaction |
Return Value:
transaction object, or null when no transaction was found
Returns the receipt of a transaction by transaction hash. The receipt is not available for pending transactions.
NimiqClient::getTransactionReceipt( string $hash ): \NimiqCommunity\RpcClient\Models\TransactionReceipt
Parameters:
Parameter | Type | Description |
---|---|---|
$hash |
string | hash of the transaction |
Return Value:
transaction receipt
Returns the latest transactions successfully performed by or for an address. This information might change when blocks are rewinded on the local state due to forks.
NimiqClient::getTransactionsByAddress( string $address, integer $limit = 1000 ): array<mixed,\NimiqCommunity\RpcClient\Models\Transaction>
Parameters:
Parameter | Type | Description |
---|---|---|
$address |
string | account address |
$limit |
integer | (optional, default 1000) number of transactions to return |
Return Value:
array of transactions linked to the requested address
Returns transactions that are currently in the mempool.
NimiqClient::getMempoolContent( boolean $includeTransactions = false ): array<mixed,string>|array<mixed,\NimiqCommunity\RpcClient\Models\Transaction>
Parameters:
Parameter | Type | Description |
---|---|---|
$includeTransactions |
boolean | 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 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).
NimiqClient::getMempool( ): \NimiqCommunity\RpcClient\Models\Mempool
Return Value:
mempool information
Returns the current minimum fee per byte.
NimiqClient::getMinFeePerByte( ): integer
Return Value:
current minimum fee per byte
Sets the minimum fee per byte.
NimiqClient::setMinFeePerByte( integer $minFee ): integer
Parameters:
Parameter | Type | Description |
---|---|---|
$minFee |
integer | minimum fee per byte |
Return Value:
new minimum fee per byte
Returns true if client is actively mining new blocks.
NimiqClient::getMiningState( ): boolean
Return Value:
true if the client is mining, otherwise false
Enables or disables the miner.
NimiqClient::setMiningState( boolean $enabled ): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
$enabled |
boolean | true to start the miner, false to stop |
Return Value:
true if the client is mining, otherwise false
Returns the number of hashes per second that the node is mining with.
NimiqClient::getHashrate( ): float
Return Value:
number of hashes per second
Returns the number of CPU threads the miner is using.
NimiqClient::getMinerThreads( ): integer
Return Value:
current number of miner threads
Sets the number of CPU threads the miner can use.
NimiqClient::setMinerThreads( integer $threads ): integer
Parameters:
Parameter | Type | Description |
---|---|---|
$threads |
integer | number of threads to allocate |
Return Value:
new number of miner threads
Returns the miner address.
NimiqClient::getMinerAddress( ): string
Return Value:
miner address
Returns the current pool.
NimiqClient::getPool( ): null|string
Return Value:
current pool, or null if not set
Sets the mining pool.
NimiqClient::setPool( boolean|string $pool ): null|string
Parameters:
Parameter | Type | Description |
---|---|---|
$pool |
boolean|string | mining pool string (url:port) or boolean to enable/disable pool mining |
Return Value:
new mining pool, or null if not enabled
Returns the connection state to mining pool.
NimiqClient::getPoolConnectionState( ): integer
Return Value:
mining pool connection state (0: connected, 1: connecting, 2: closed)
Returns the confirmed mining pool balance.
NimiqClient::getPoolConfirmedBalance( ): float
Return Value:
confirmed mining pool balance (in smallest unit)
Returns instructions to mine the next block. This will consider pool instructions when connected to a pool.
NimiqClient::getWork( string $address = null, string $extraDataHex = null ): array
Parameters:
Parameter | Type | Description |
---|---|---|
$address |
string | address to use as a miner for this block. this overrides the address provided during startup or from the pool. |
$extraDataHex |
string | hex-encoded value for the extra data field. this overrides the address provided during startup or from the pool. |
Return Value:
mining work instructions
Returns a template to build the next block for mining. This will consider pool instructions when connected to a pool.
NimiqClient::getBlockTemplate( string $address = null, string $extraDataHex = null ): array
Parameters:
Parameter | Type | Description |
---|---|---|
$address |
string | address to use as a miner for this block. this overrides the address provided during startup or from the pool. |
$extraDataHex |
string | hex-encoded value for the extra data field. this overrides the address provided during startup or from the pool. |
Return Value:
mining block template
Submits a block to the node. When the block is valid, the node will forward it to other nodes in the network.
NimiqClient::submitBlock( string $blockHex )
Parameters:
Parameter | Type | Description |
---|---|---|
$blockHex |
string | hex-encoded full block (including header, interlink and body). when submitting work from getWork, remember to include the suffix. |
Returns a list of addresses owned by client.
NimiqClient::getAccounts( ): array<mixed,\NimiqCommunity\RpcClient\Models\Account>|array<mixed,\NimiqCommunity\RpcClient\Models\VestingContract>|array<mixed,\NimiqCommunity\RpcClient\Models\HashedTimeLockedContract>
Return Value:
array of accounts owned by the client
Creates a new account and stores its private key in the client store.
NimiqClient::createAccount( ): \NimiqCommunity\RpcClient\Models\Wallet
Return Value:
information on the wallet that was created using the command
Returns the balance of the account of given address.
NimiqClient::getBalance( string $address ): float
Parameters:
Parameter | Type | Description |
---|---|---|
$address |
string | address to check for balance |
Return Value:
the current balance at the specified address (in smallest unit)
Returns details for the account of given address.
NimiqClient::getAccount( string $address ): \NimiqCommunity\RpcClient\Models\Account|\NimiqCommunity\RpcClient\Models\VestingContract|\NimiqCommunity\RpcClient\Models\HashedTimeLockedContract
Parameters:
Parameter | Type | Description |
---|---|---|
$address |
string | address for which to get account details |
Return Value:
details about the account. returns the default empty basic account for non-existing accounts.
Returns the height of most recent block.
NimiqClient::getBlockNumber( ): integer
Return Value:
current block height the client is on
Returns the number of transactions in a block from a block matching the given block hash.
NimiqClient::getBlockTransactionCountByHash( string $blockHash ): null|integer
Parameters:
Parameter | Type | Description |
---|---|---|
$blockHash |
string | hash of the block |
Return Value:
number of transactions in the block found, or null when no block was found
Returns the number of transactions in a block matching the given block number.
NimiqClient::getBlockTransactionCountByNumber( integer $blockNumber ): null|integer
Parameters:
Parameter | Type | Description |
---|---|---|
$blockNumber |
integer | height of the block |
Return Value:
number of transactions in the block found, or null when no block was found
Returns information about a block by hash.
NimiqClient::getBlockByHash( string $blockHash, boolean $includeTransactions = false ): null|\NimiqCommunity\RpcClient\Models\Block
Parameters:
Parameter | Type | Description |
---|---|---|
$blockHash |
string | hash of the block to gather information on |
$includeTransactions |
boolean | if true includes full transactions, if false (default) includes only transaction hashes |
Return Value:
block object, or null when no block was found
Returns information about a block by block number.
NimiqClient::getBlockByNumber( integer $blockNumber, boolean $includeTransactions = false ): null|\NimiqCommunity\RpcClient\Models\Block
Parameters:
Parameter | Type | Description |
---|---|---|
$blockNumber |
integer | height of the block to gather information on |
$includeTransactions |
boolean | if true includes full transactions, if false (default) includes only transaction hashes |
Return Value:
block object, or null when no block was found
Returns the value of a constant.
NimiqClient::getConstant( string $constant ): integer
Parameters:
Parameter | Type | Description |
---|---|---|
$constant |
string | name of the constant |
Return Value:
current value of the constant
Sets the value of a constants.
NimiqClient::setConstant( string $constant, integer $value ): integer
Parameters:
Parameter | Type | Description |
---|---|---|
$constant |
string | name of the constant |
$value |
integer | value to set |
Return Value:
new value of the constant
Resets the constant to default value.
NimiqClient::resetConstant( string $constant ): integer
Parameters:
Parameter | Type | Description |
---|---|---|
$constant |
string | name of the constant |
Return Value:
new value of the constant
Sets the log level of the node.
NimiqClient::setLogLevel( string $tag, string $level ): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
$tag |
string | if '*' the log level is set globally, otherwise the log level is applied only on this tag |
$level |
string | minimum log level to display (trace, verbose, debug, info, warn, error, assert) |
Return Value:
true if set successfully, otherwise false
This document was automatically generated from source code comments on 2020-06-17 using phpDocumentor and cvuorinen/phpdoc-markdown-public