Ethereum PHP
PHP interface to Ethereum JSON-RPC API.
Ethereum Class Reference
+ Inheritance diagram for Ethereum:
+ Collaboration diagram for Ethereum:

Public Member Functions

 __construct (string $url='http://localhost:8545')
 
 __call (string $method, array $args)
 
 request (string $method, array $params=[])
 
 etherRequest (string $method, array $params=[])
 
 debug (string $title, $content=null)
 
- Public Member Functions inherited from Web3Interface
 web3_clientVersion ()
 
 web3_sha3 (EthS $arg1)
 
 net_version ()
 
 net_peerCount ()
 
 net_listening ()
 
 personal_sign (EthD20 $arg1, EthD $arg2, EthS $arg3)
 
 personal_ecRecover (EthD $arg1, EthD $arg2)
 
 eth_protocolVersion ()
 
 eth_syncing ()
 
 eth_coinbase ()
 
 eth_mining ()
 
 eth_hashrate ()
 
 eth_gasPrice ()
 
 eth_accounts ()
 
 eth_blockNumber ()
 
 eth_getBalance (EthD20 $arg1, EthBlockParam $arg2)
 
 eth_getStorageAt (EthD20 $arg1, EthQ $arg2, EthBlockParam $arg3)
 
 eth_getTransactionCount (EthD20 $arg1, EthBlockParam $arg2)
 
 eth_getBlockTransactionCountByHash (EthD32 $arg1)
 
 eth_getBlockTransactionCountByNumber (EthBlockParam $arg1)
 
 eth_getUncleCountByBlockHash (EthD32 $arg1)
 
 eth_getUncleCountByBlockNumber (EthQ $arg1)
 
 eth_getCode (EthD20 $arg1, EthBlockParam $arg2)
 
 eth_sign (EthD20 $arg1, EthD32 $arg2)
 
 eth_sendTransaction (SendTransaction $arg1)
 
 eth_sendRawTransaction (EthD $arg1)
 
 eth_call (CallTransaction $arg1, EthBlockParam $arg2)
 
 eth_estimateGas (EstimateTransaction $arg1, EthBlockParam $arg2)
 
 eth_getBlockByHash (EthD32 $arg1, EthB $arg2)
 
 eth_getBlockByNumber (EthBlockParam $arg1, EthB $arg2)
 
 eth_getTransactionByHash (EthD32 $arg1)
 
 eth_getTransactionByBlockHashAndIndex (EthD32 $arg1, EthQ $arg2)
 
 eth_getTransactionByBlockNumberAndIndex (EthBlockParam $arg1, EthQ $arg2)
 
 eth_getTransactionReceipt (EthD32 $arg1)
 
 eth_getUncleByBlockHashAndIndex (EthD32 $arg1, EthQ $arg2)
 
 eth_getUncleByBlockNumberAndIndex (EthBlockParam $arg1, EthQ $arg2)
 
 eth_getCompilers ()
 
 eth_compileLLL (EthS $arg1)
 
 eth_compileSolidity (EthS $arg1)
 
 eth_compileSerpent (EthS $arg1)
 
 eth_newFilter (Filter $arg1)
 
 eth_newBlockFilter ()
 
 eth_newPendingTransactionFilter ()
 
 eth_uninstallFilter (EthQ $arg1)
 
 eth_getFilterChanges (EthQ $arg1)
 
 eth_getFilterLogs (EthQ $arg1)
 
 eth_getLogs (Filter $arg1)
 
 eth_getWork ()
 
 eth_submitWork (EthD $arg1, EthD32 $arg2, EthD32 $arg3)
 
 eth_submitHashrate (EthD $arg1, EthD $arg2)
 
 db_putString (EthS $arg1, EthS $arg2, EthS $arg3)
 
 db_getString (EthS $arg1, EthS $arg2)
 
 db_putHex (EthS $arg1, EthS $arg2, EthD $arg3)
 
 db_getHex (EthS $arg1, EthS $arg2)
 
 shh_post (SHHPost $arg1)
 
 shh_version ()
 
 shh_newIdentity ()
 
 shh_hasIdentity (EthD $arg1)
 
 shh_newGroup ()
 
 shh_addToGroup (EthD $arg1)
 
 shh_newFilter (SHHFilter $arg1)
 
 shh_uninstallFilter (EthQ $arg1)
 
 shh_getFilterChanges (EthQ $arg1)
 
 shh_getMessages (EthQ $arg1)
 

Static Public Member Functions

static personalEcRecover (string $message, EthD $signature)
 
static valueArray (array $values, string $typeClass)
 
- Static Public Member Functions inherited from EthereumStatic
static getMethodSignature ($input)
 
static phpKeccak256 ($string)
 
static sha3 ($string)
 
static isValidFunction ($input)
 
static getDefinition ()
 
static isValidHexQuantity ($str)
 
static isValidHexData ($str)
 
static isValidAddress ($address, $throw=false)
 
static hasHexPrefix ($str)
 
static removeHexPrefix ($str)
 
static ensureHexPrefix ($str)
 
static convertCurrency (float $amount, string $from='wei', string $to='ether')
 

Public Attributes

 $client
 
 $debugHtml = ''
 

Static Protected Member Functions

static isArrayType (string $type)
 
static handleFilterChangeValues (array $values)
 

Detailed Description

Ethereum Web3 API for PHP.

Definition at line 39 of file Ethereum.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( string  $url = 'http://localhost:8545')

Constructing Ethereum Class.

Remarks: Ethereum class is based on ethjs-schema.json file.

  • Everything is typed. All data types extend EthDataType class.
  • Primitive data have a mostly common interface. See EthD.
  • Complex data types (See "objects" in schema.json) are generated by script. This guarantees consistent type handling. Changes to the generated need to be implemented in make_datatypes.php.
  • Methods are typed based on ethjs-schema and implemented as Closure calls, which makes this constructor complex, but ensures consistent typing.
Parameters
string$urlConnection to Ethereum node. E.g: http://localhost:8545 or https://mainnet.infura.io/drupal.

Definition at line 69 of file Ethereum.php.

References EthD\typeMap().

+ Here is the call graph for this function:

Member Function Documentation

◆ __call()

__call ( string  $method,
array  $args 
)

Method call wrapper.

Parameters
string$method
array$args
Returns
mixed

Definition at line 234 of file Ethereum.php.

References EthDataType\getTypeClass().

+ Here is the call graph for this function:

◆ debug()

debug ( string  $title,
  $content = null 
)

Debug Helper.

Parameters
string$titleAny HTML. Will be printed bold.
string | object | array$contentContent will be printed in appropriate format.
Returns
string Debug HTML output.

Definition at line 385 of file Ethereum.php.

◆ etherRequest()

etherRequest ( string  $method,
array  $params = [] 
)

Ethereum request.

Parameters
string$method
array$params
Exceptions

Definition at line 356 of file Ethereum.php.

◆ handleFilterChangeValues()

static handleFilterChangeValues ( array  $values)
staticprotected

handleFilterChangeValues().

The return values for getFilterChange are not consistently implemented in the schema.

See also
https://github.com/ethjs/ethjs-schema/issues/10

See also https://github.com/ethereum/wiki/wiki/JSON-RPC#returns-42

Parameters
$valuesarray
Exceptions
Todo:
We'll need to decode the ABI of the values too!

Definition at line 420 of file Ethereum.php.

References FilterChange\getTypeArray(), and EthDataType\getTypeClass().

+ Here is the call graph for this function:

◆ isArrayType()

static isArrayType ( string  $type)
staticprotected

Note if there are still Arrays passed here we crash. Array types should be insicated by "[TYPE]" or type[].

Parameters
string$type
Returns
bool

Definition at line 326 of file Ethereum.php.

◆ personalEcRecover()

static personalEcRecover ( string  $message,
EthD  $signature 
)
static

PersonalEcRecover function.

Parameters
string$messageUTF-8 text.
EthD$signatureHex value of the Message Signature.
Exceptions
Exception
Returns
string EthereumAddress with prefix.

Definition at line 551 of file Ethereum.php.

References EthD\hexVal().

+ Here is the call graph for this function:

◆ request()

request ( string  $method,
array  $params = [] 
)

Request().

Parameters
string$methodJsonRPC method to be called.
array$paramsRequest parameters. See Guzzle doc.
Returns
mixed

Definition at line 339 of file Ethereum.php.

◆ valueArray()

static valueArray ( array  $values,
string  $typeClass 
)
static

Create value array.

Turns a array('0x56789...', ...) into array(EthD32(0x56789...), ...)

Parameters
array$valuesArray of values of a unique data type.
string$typeClassClass name for the data type.
Exceptions
Exception
Returns
array Array of value objects of the given type.

Definition at line 571 of file Ethereum.php.

Referenced by SHHFilter\toArray(), Filter\toArray(), SHHPost\toArray(), SHHFilterChange\toArray(), Receipt\toArray(), SHHMessage\toArray(), FilterChange\toArray(), and Block\toArray().

+ Here is the caller graph for this function:

Member Data Documentation

◆ $client

$client

Definition at line 48 of file Ethereum.php.

◆ $debugHtml

$debugHtml = ''

Definition at line 49 of file Ethereum.php.


The documentation for this class was generated from the following file: