Documentation

HttpRPC extends AbstractRPC
in package

HttpRPC provides functionality to make JSON-RPC calls over HTTP / HTTPS via curl. Curl handle persist across calls.

Tags
author

DubbaThony

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

$headers

private array<string|int, mixed> $headers = []

$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
throws
InvalidURLException

if the provided URL is not valid or uses unsupported protocols.

__destruct()

Closes the cURL handle on object destruction.

public __destruct() : mixed

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
throws
BadAddressChecksumException
throws
EthBinderArgumentException
throws
EthBinderLogicException
throws
InvalidHexException
throws
InvalidHexLengthException
throws
RPCGeneralException
throws
RPCInvalidResponseParamException
throws
RPCNotFoundException
Return values
array<string|int, Log>

ethNewFilter()

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
throws
EthBinderArgumentException
throws
RPCGeneralException
throws
RPCInvalidResponseParamException
throws
RPCNotFoundException
throws
EthBinderLogicException
Return values
OOGmp

raw()

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
inheritDoc
throws
RPCGeneralException

if the request fails or response is invalid.

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
throws
RPCGeneralException

if any unexpected error is present in RPC response

throws
RPCInvalidResponseParamException

if the 'result' field is missing in the response

throws
RPCNotFoundException

if the method is not found

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.

blockHash()

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
$block : Hash|Block
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
throws
EthBinderLogicException
throws
EthBinderArgumentException
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
Return values
array<string|int, mixed>

        
On this page

Search results