HttpRPC
extends AbstractRPC
in package
HttpRPC provides functionality to make JSON-RPC calls over HTTP / HTTPS via curl. Curl handle persist across calls.
Tags
Table of Contents
Constants
- DEFAULT_TIP_WEI = 1
Properties
- $cachedChainId : int|null
- $ch : CurlHandle
- $headers : array<string|int, mixed>
- $id : int
- $seemsLondon : bool|null
Methods
- __construct() : mixed
- Constructs a new HttpRPC object.
- __destruct() : mixed
- Closes the cURL handle on object destruction.
- calcAvgTip() : OOGmp
- Calculates the average EIP1559 tip over a range of blocks. If the underlying chain doesn't look like EIP1559 chain, it returns fallback of 1 GWEI.
- debugGetRawBlock() : array<string|int, mixed>
- debugGetRawHeader() : array<string|int, mixed>
- debugGetRawReceipts() : array<string|int, mixed>
- debugGetRawTransaction() : Transaction
- ethAccounts() : array<string|int, Address>
- ethBlockNumber() : int
- ethCall() : string
- ethChainID() : int
- ethCoinbase() : Address
- ethEstimateGas() : int
- ethGasPrice() : OOGmp
- ethGetBalance() : OOGmp
- ethGetBlockByHash() : Block
- ethGetBlockByNumber() : Block
- ethGetBlockTransactionCountByHash() : int
- ethGetBlockTransactionCountByNumber() : int
- ethGetCode() : string
- ethGetFilterChanges() : array<string|int, mixed>
- ethGetFilterLogs() : array<string|int, Log>
- ethGetLogs() : array<string|int, Log>
- ethGetStorageAt() : OOGmp
- ethGetTransactionByBlockHashAndIndex() : Transaction
- ethGetTransactionByBlockNumberAndIndex() : Transaction
- ethGetTransactionByHash() : Transaction
- ethGetTransactionCount() : OOGmp
- ethGetTransactionReceipt() : Receipt
- ethGetUncleByBlockHashAndIndex() : Block
- ethGetUncleByBlockNumberAndIndex() : Block
- ethGetUncleCountByBlockHash() : int
- ethGetUncleCountByBlockNumber() : int
- ethHashrate() : OOGmp
- ethMaxPriorityFeePerGas() : OOGmp
- ethMining() : bool
- ethNewFilter() : OOGmp
- Installs event filterer on rpc node and returns ID of the filter. Accepts few types, but bear in mind that string type is always considered to be binary blob.
- ethProtocolVersion() : int
- ethSendRawTransaction() : Hash
- ethSendRawTransactionHex() : Hash
- ethSendTransaction() : Hash
- ethSign() : string
- ethSignTransaction() : string
- ethSyncing() : false|array<string|int, mixed>
- isLookingLikeLondon() : bool
- Checks whether the network seems to be like London (EIP-1559) by checking block data fields that are EIP1559 specific
- netListening() : bool
- netPeerCount() : int
- netVersion() : int
- raw() : array<string|int, mixed>
- Sends a raw RPC request using underlying protocol.
- runRpc() : array<string|int, mixed>
- Sends an RPC request and returns only the 'result' data.
- web3ClientVersion() : string
- web3Sha3Keccak() : Hash
- web3Sha3KeccakBin() : Hash
- blockHash() : string
- Either extracts block hash from block and returns it as hex string, or returns hash hex string. Used for parameter normalization in RPC calls, for convenience of API.
- blockParam() : string
- Normalizes a block number parameter for RPC calls.
- parseFilterInput() : array<string|int, mixed>
- transactionToRPCArr() : array<string|int, mixed>
Constants
DEFAULT_TIP_WEI
private
mixed
DEFAULT_TIP_WEI
= 1
Properties
$cachedChainId
private
int|null
$cachedChainId
= null
$ch
private
CurlHandle
$ch
$headers
private
array<string|int, mixed>
$headers
= []
$id
private
int
$id
= 1
$seemsLondon
private
bool|null
$seemsLondon
= null
Methods
__construct()
Constructs a new HttpRPC object.
public
__construct(string $url[, array<string|int, mixed> $extraHeaders = [] ]) : mixed
Parameters
- $url : string
-
Endpoint URL for JSON-RPC calls.
- $extraHeaders : array<string|int, mixed> = []
-
Additional HTTP headers.
Tags
__destruct()
Closes the cURL handle on object destruction.
public
__destruct() : mixed
calcAvgTip()
Calculates the average EIP1559 tip over a range of blocks. If the underlying chain doesn't look like EIP1559 chain, it returns fallback of 1 GWEI.
public
calcAvgTip([int $blockNumbers = 3 ]) : OOGmp
Parameters
- $blockNumbers : int = 3
-
number of recent blocks to consider
Tags
Return values
OOGmp —average tip across considered blocks
debugGetRawBlock()
public
debugGetRawBlock([int|BlockParam $blockParam = BlockParam::LATEST ]) : array<string|int, mixed>
Parameters
- $blockParam : int|BlockParam = BlockParam::LATEST
Tags
Return values
array<string|int, mixed>debugGetRawHeader()
public
debugGetRawHeader([int|BlockParam $blockParam = BlockParam::LATEST ]) : array<string|int, mixed>
Parameters
- $blockParam : int|BlockParam = BlockParam::LATEST
Tags
Return values
array<string|int, mixed>debugGetRawReceipts()
public
debugGetRawReceipts([int|BlockParam $blockParam = BlockParam::LATEST ]) : array<string|int, mixed>
Parameters
- $blockParam : int|BlockParam = BlockParam::LATEST
Tags
Return values
array<string|int, mixed>debugGetRawTransaction()
public
debugGetRawTransaction(Hash $h) : Transaction
Parameters
- $h : Hash
Tags
Return values
TransactionethAccounts()
public
ethAccounts() : array<string|int, Address>
Tags
Return values
array<string|int, Address>ethBlockNumber()
public
ethBlockNumber() : int
Tags
Return values
intethCall()
public
ethCall(Transaction $message[, Address|null $from = null ][, int|BlockParam $blockParam = BlockParam::LATEST ]) : string
Parameters
- $message : Transaction
- $from : Address|null = null
- $blockParam : int|BlockParam = BlockParam::LATEST
Tags
Return values
stringethChainID()
public
ethChainID() : int
Tags
Return values
intethCoinbase()
public
ethCoinbase() : Address
Tags
Return values
AddressethEstimateGas()
public
ethEstimateGas(Transaction $txn, Address|null $from) : int
Parameters
- $txn : Transaction
- $from : Address|null
Tags
Return values
intethGasPrice()
public
ethGasPrice() : OOGmp
Tags
Return values
OOGmpethGetBalance()
public
ethGetBalance(Address $address[, int|BlockParam $blockParam = BlockParam::LATEST ]) : OOGmp
Parameters
- $address : Address
- $blockParam : int|BlockParam = BlockParam::LATEST
Tags
Return values
OOGmpethGetBlockByHash()
public
ethGetBlockByHash(Hash $hash[, bool $fullBlock = false ]) : Block
Parameters
- $hash : Hash
- $fullBlock : bool = false
Tags
Return values
BlockethGetBlockByNumber()
public
ethGetBlockByNumber([int|BlockParam $blockParam = BlockParam::LATEST ][, bool $fullBlock = false ]) : Block
Parameters
- $blockParam : int|BlockParam = BlockParam::LATEST
- $fullBlock : bool = false
Tags
Return values
BlockethGetBlockTransactionCountByHash()
public
ethGetBlockTransactionCountByHash(Hash|Block $block) : int
Parameters
Tags
Return values
intethGetBlockTransactionCountByNumber()
public
ethGetBlockTransactionCountByNumber([int|BlockParam $blockParam = BlockParam::LATEST ]) : int
Parameters
- $blockParam : int|BlockParam = BlockParam::LATEST
Tags
Return values
intethGetCode()
public
ethGetCode(Address $address[, int|BlockParam $blockParam = BlockParam::LATEST ]) : string
Parameters
- $address : Address
- $blockParam : int|BlockParam = BlockParam::LATEST
Tags
Return values
stringethGetFilterChanges()
public
ethGetFilterChanges(OOGmp $filterId) : array<string|int, mixed>
Parameters
- $filterId : OOGmp
Tags
Return values
array<string|int, mixed>ethGetFilterLogs()
public
ethGetFilterLogs(OOGmp $filterId) : array<string|int, Log>
Parameters
- $filterId : OOGmp
Tags
Return values
array<string|int, Log>ethGetLogs()
public
ethGetLogs(Address|array<string|int, mixed> $address, int|BlockParam|null $fromBlock, int|BlockParam|null $toBlock, Hash|null $blockHash, string|bool|HashSerializable|array<string|int, mixed> $topic0[, string|bool|HashSerializable|array<string|int, mixed>|null $topic1 = null ][, string|bool|HashSerializable|array<string|int, mixed>|null $topic2 = null ][, string|bool|HashSerializable|array<string|int, mixed>|null $topic3 = null ]) : array<string|int, Log>
Parameters
- $address : Address|array<string|int, mixed>
- $fromBlock : int|BlockParam|null
-
if $blockHash not null, it MUST be null
- $toBlock : int|BlockParam|null
-
if $blockHash not null, it MUST be null
- $blockHash : Hash|null
-
if $fromBlock and/or $toBlock is not null, it MUST be null
- $topic0 : string|bool|HashSerializable|array<string|int, mixed>
- $topic1 : string|bool|HashSerializable|array<string|int, mixed>|null = null
- $topic2 : string|bool|HashSerializable|array<string|int, mixed>|null = null
- $topic3 : string|bool|HashSerializable|array<string|int, mixed>|null = null
Tags
Return values
array<string|int, Log>ethGetStorageAt()
public
ethGetStorageAt(Address $address, OOGmp $position[, int|BlockParam $blockParam = BlockParam::LATEST ]) : OOGmp
Parameters
- $address : Address
- $position : OOGmp
- $blockParam : int|BlockParam = BlockParam::LATEST
Tags
Return values
OOGmpethGetTransactionByBlockHashAndIndex()
public
ethGetTransactionByBlockHashAndIndex(Hash $hash, int $index) : Transaction
Parameters
- $hash : Hash
- $index : int
Tags
Return values
TransactionethGetTransactionByBlockNumberAndIndex()
public
ethGetTransactionByBlockNumberAndIndex(int|BlockParam $blockParam, int $index) : Transaction
Parameters
- $blockParam : int|BlockParam
- $index : int
Tags
Return values
TransactionethGetTransactionByHash()
public
ethGetTransactionByHash(Hash $hash) : Transaction
Parameters
- $hash : Hash
Tags
Return values
TransactionethGetTransactionCount()
public
ethGetTransactionCount(Address $address[, int|BlockParam $blockParam = BlockParam::PENDING ]) : OOGmp
Parameters
- $address : Address
- $blockParam : int|BlockParam = BlockParam::PENDING
Tags
Return values
OOGmpethGetTransactionReceipt()
public
ethGetTransactionReceipt(Hash $hash) : Receipt
Parameters
- $hash : Hash
Tags
Return values
ReceiptethGetUncleByBlockHashAndIndex()
public
ethGetUncleByBlockHashAndIndex(Hash $hash, int $unclePos) : Block
Parameters
- $hash : Hash
- $unclePos : int
Tags
Return values
BlockethGetUncleByBlockNumberAndIndex()
public
ethGetUncleByBlockNumberAndIndex(int|BlockParam $blockParam, int $unclePos) : Block
Parameters
- $blockParam : int|BlockParam
- $unclePos : int
Tags
Return values
BlockethGetUncleCountByBlockHash()
public
ethGetUncleCountByBlockHash(Hash|Block $block) : int
Parameters
Tags
Return values
intethGetUncleCountByBlockNumber()
public
ethGetUncleCountByBlockNumber([int|BlockParam $blockParam = BlockParam::LATEST ]) : int
Parameters
- $blockParam : int|BlockParam = BlockParam::LATEST
Tags
Return values
intethHashrate()
public
ethHashrate() : OOGmp
Tags
Return values
OOGmpethMaxPriorityFeePerGas()
public
ethMaxPriorityFeePerGas() : OOGmp
Tags
Return values
OOGmpethMining()
public
ethMining() : bool
Tags
Return values
boolethNewFilter()
Installs event filterer on rpc node and returns ID of the filter. Accepts few types, but bear in mind that string type is always considered to be binary blob.
public
ethNewFilter(Address|array<string|int, Address> $address, int|BlockParam|null $fromBlock, int|BlockParam|null $toBlock, string|bool|HashSerializable|array<string|int, string>|array<string|int, bool>|array<string|int, HashSerializable> $topic0[, null|string|bool|HashSerializable|array<string|int, string>|array<string|int, bool>|array<string|int, HashSerializable> $topic1 = null ][, null|string|bool|HashSerializable|array<string|int, string>|array<string|int, bool>|array<string|int, HashSerializable> $topic2 = null ][, null|string|bool|HashSerializable|array<string|int, string>|array<string|int, bool>|array<string|int, HashSerializable> $topic3 = null ]) : OOGmp
Parameters
- $address : Address|array<string|int, Address>
- $fromBlock : int|BlockParam|null
- $toBlock : int|BlockParam|null
- $topic0 : string|bool|HashSerializable|array<string|int, string>|array<string|int, bool>|array<string|int, HashSerializable>
- $topic1 : null|string|bool|HashSerializable|array<string|int, string>|array<string|int, bool>|array<string|int, HashSerializable> = null
- $topic2 : null|string|bool|HashSerializable|array<string|int, string>|array<string|int, bool>|array<string|int, HashSerializable> = null
- $topic3 : null|string|bool|HashSerializable|array<string|int, string>|array<string|int, bool>|array<string|int, HashSerializable> = null
Tags
Return values
OOGmpethProtocolVersion()
public
ethProtocolVersion() : int
Tags
Return values
intethSendRawTransaction()
public
ethSendRawTransaction(Transaction $signedTransaction) : Hash
Parameters
- $signedTransaction : Transaction
Tags
Return values
HashethSendRawTransactionHex()
public
ethSendRawTransactionHex(string $rawTransactionHex) : Hash
Parameters
- $rawTransactionHex : string
Tags
Return values
HashethSendTransaction()
public
ethSendTransaction(Transaction $txn, Address $from) : Hash
Parameters
- $txn : Transaction
- $from : Address
Tags
Return values
HashethSign()
public
ethSign(Address $address, string $dataHex) : string
Parameters
- $address : Address
- $dataHex : string
Tags
Return values
stringethSignTransaction()
public
ethSignTransaction(Transaction $txn, Address $from) : string
Parameters
- $txn : Transaction
- $from : Address
Tags
Return values
stringethSyncing()
public
ethSyncing() : false|array<string|int, mixed>
Tags
Return values
false|array<string|int, mixed>isLookingLikeLondon()
Checks whether the network seems to be like London (EIP-1559) by checking block data fields that are EIP1559 specific
public
isLookingLikeLondon() : bool
Tags
Return values
bool —true if network seems to be post-London fork, false otherwise
netListening()
public
netListening() : bool
Tags
Return values
boolnetPeerCount()
public
netPeerCount() : int
Tags
Return values
intnetVersion()
public
netVersion() : int
Tags
Return values
intraw()
Sends a raw RPC request using underlying protocol.
public
raw(string $method[, array<string|int, mixed>|null $params = null ]) : array<string|int, mixed>
Parameters
- $method : string
-
the RPC method to call
- $params : array<string|int, mixed>|null = null
-
optional parameters for the method
Tags
Return values
array<string|int, mixed> —full body of RPC response as an array
runRpc()
Sends an RPC request and returns only the 'result' data.
public
runRpc(string $method[, array<string|int, mixed>|null $params = null ]) : array<string|int, mixed>
Parameters
- $method : string
-
the RPC method to call
- $params : array<string|int, mixed>|null = null
-
optional parameters for the method
Tags
Return values
array<string|int, mixed> —'result' field of the RPC response. If the result is not an array, it's wrapped in an array under key 0.
web3ClientVersion()
public
web3ClientVersion() : string
Tags
Return values
stringweb3Sha3Keccak()
public
web3Sha3Keccak(string $inputHex) : Hash
Parameters
- $inputHex : string
Tags
Return values
Hashweb3Sha3KeccakBin()
public
web3Sha3KeccakBin(string $inputBin) : Hash
Parameters
- $inputBin : string
Tags
Return values
HashblockHash()
Either extracts block hash from block and returns it as hex string, or returns hash hex string. Used for parameter normalization in RPC calls, for convenience of API.
protected
blockHash(Hash|Block $block) : string
@param Hash|Block $block the block object or a Hash object
Parameters
Return values
string —hexadecimal representation of the block hash
blockParam()
Normalizes a block number parameter for RPC calls.
protected
blockParam(int|BlockParam $blockNumber) : string
Parameters
- $blockNumber : int|BlockParam
-
the block number or a BlockParam object
Return values
string —hexadecimal representation of the block number or RPC alias string, such as "latest"
parseFilterInput()
protected
parseFilterInput(Address|array<string|int, mixed> $address, null|int|BlockParam $fromBlock, null|int|BlockParam $toBlock, null|Hash $blockHash, string|bool|HashSerializable|array<string|int, mixed> $topic0[, null|string|bool|HashSerializable|array<string|int, mixed> $topic1 = null ][, null|string|bool|HashSerializable|array<string|int, mixed> $topic2 = null ][, null|string|bool|HashSerializable|array<string|int, mixed> $topic3 = null ]) : array<string|int, mixed>
Parameters
- $address : Address|array<string|int, mixed>
- $fromBlock : null|int|BlockParam
- $toBlock : null|int|BlockParam
- $blockHash : null|Hash
- $topic0 : string|bool|HashSerializable|array<string|int, mixed>
- $topic1 : null|string|bool|HashSerializable|array<string|int, mixed> = null
- $topic2 : null|string|bool|HashSerializable|array<string|int, mixed> = null
- $topic3 : null|string|bool|HashSerializable|array<string|int, mixed> = null
Tags
Return values
array<string|int, mixed>transactionToRPCArr()
private
transactionToRPCArr(Transaction $txn, Address|null $from[, bool $asMessage = false ]) : array<string|int, mixed>
Parameters
- $txn : Transaction
- $from : Address|null
- $asMessage : bool = false