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

Static Public Member Functions

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')
 

Detailed Description

Static helper functions for Ethereum JsonRPC API for PHP.

Definition at line 10 of file EthereumStatic.php.

Member Function Documentation

◆ convertCurrency()

static convertCurrency ( float  $amount,
string  $from = 'wei',
string  $to = 'ether' 
)
static

Convert from and to ether Ether

Defaults from wei to ether.

Parameters
float$amount
string$from
string$to
Exceptions

Definition at line 291 of file EthereumStatic.php.

◆ ensureHexPrefix()

static ensureHexPrefix (   $str)
static

Add Hex Prefix "0x".

Parameters
string$strString without prefix.
Returns
string String with prefix.

Definition at line 271 of file EthereumStatic.php.

Referenced by EthS\hexVal(), EthBlockParam\hexVal(), EthBytes\validate(), and EthD\validate().

+ Here is the caller graph for this function:

◆ getDefinition()

static getDefinition ( )
static

Retrieve the Ethereum JsonRPC API definition.

Normally the content of the file resources/ethjs-schema.json.

Returns
array

Definition at line 124 of file EthereumStatic.php.

Referenced by EthDataType\getAllTypeClasses().

+ Here is the caller graph for this function:

◆ getMethodSignature()

static getMethodSignature (   $input)
static

Get signature of a solidity method.

Returns hash of the Smart contract method - it's signature.

See: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI#function-selector

Parameters
string$inputMethod signature.
Exceptions

Definition at line 29 of file EthereumStatic.php.

◆ hasHexPrefix()

static hasHexPrefix (   $str)
static

Test if a string is prefixed with "0x".

Parameters
string$strString to test prefix.
Returns
bool TRUE if string has "0x" prefix or FALSE.

Definition at line 239 of file EthereumStatic.php.

Referenced by EthS\validate(), and EthQ\validate().

+ Here is the caller graph for this function:

◆ isValidAddress()

static isValidAddress (   $address,
  $throw = false 
)
static

Check for a valid Ethereum address.

Tests if the given string qualifies as a Ethereum address. (DATA, 20 Bytes - address)

Parameters
string$addressString to test for Address.
bool$throwIf TRUE we will throw en error.
Returns
bool TRUE if string is a Valid Address value or FALSE.

Definition at line 216 of file EthereumStatic.php.

References $address.

◆ isValidFunction()

static isValidFunction (   $input)
static

Is valid function.

Todo:
Pretty basic solidity function verification might need improvement.

"The signature is defined as the canonical expression of the basic prototype, i.e. the function name with the parenthesised list of parameter types."

See also
http://solidity.readthedocs.io/en/develop/abi-spec.html#function-selector

This function ignores Aliases. E.g: test(uint) test(uint256) should both result in 0x29e99f07. This is intentional. It is not recommended to use short names for function signatures.

Parameters
string$inputFunction ABI as string. See: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI.
Returns
bool True if it is a valid solidity function.

Definition at line 105 of file EthereumStatic.php.

◆ isValidHexData()

static isValidHexData (   $str)
static

Tests if the given string is a HEX UNFORMATED DATA value.

See: https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding.

Parameters
string$strString to test for Hex.
Returns
bool TRUE if string is a Valid Hex value or FALSE.

Definition at line 182 of file EthereumStatic.php.

◆ isValidHexQuantity()

static isValidHexQuantity (   $str)
static

Decodes a HEX encoded number.

See: https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding.

This is now handled by Math_BigInteger https://pear.php.net/package/Math_BigInteger/docs/latest/Math_BigInteger/Math_BigInteger.html.

See class EthQ. Tests string for valid hex quantity.

See: https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding.

Parameters
string$strString to test for Hex.
Returns
bool TRUE if string is a Valid Hex value or FALSE.

Definition at line 154 of file EthereumStatic.php.

◆ phpKeccak256()

static phpKeccak256 (   $string)
static

Keccak hash function.

This is a a local version of web3_sha3() based on https://github.com/kornrunner/php-keccak

Ethereum JsonRPC provides web3.sha3(), but making a JsonRPC call for that seems costly.

Unlike web3's sha3 method suggests Ethereum is NOT using SHA3-256 standard implementation (the NIST SHA3-256 became a standard later), but Keccak256. Is is the pure Keccak[r=1088, c=512] implementation.

Parameters
string$stringString to hash.
Returns
string Keccak256 of the provided string.

Definition at line 61 of file EthereumStatic.php.

◆ removeHexPrefix()

static removeHexPrefix (   $str)
static

Remove Hex Prefix "0x".

Parameters
string$strString with prefix.
Returns
string String without prefix.

Definition at line 253 of file EthereumStatic.php.

Referenced by EthBytes\val(), and EthBytes\validate().

+ Here is the caller graph for this function:

◆ sha3()

static sha3 (   $string)
static

Wrapper to phpKeccak256($string).

Ethereum sha3 is not the same as the standardized sha3.

See also
: https://ethereum.stackexchange.com/questions/30369/difference-between-keccak256-and-sha3

As web3js provides a sha3() method we have this wrapper for convenience.

Parameters
$stringString to hash.
Returns
string Hash of input.

Definition at line 80 of file EthereumStatic.php.


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