Skip to content

Latest commit

 

History

History
125 lines (82 loc) · 3.25 KB

API.md

File metadata and controls

125 lines (82 loc) · 3.25 KB

API development

Schema based API

In order to keep this API up do date it is build schema based. (resources/ethjs-schema.json)

Ethereum JsonRPC Methods are on ethereum-schema->methods. Implemented in Ethereum class. Check out the Web3Interface.

To regenerate src/Web3Methods.php and src/Web3Interface.php run

composer run-script generate-methods

Complex Data types are generated ethereum-schema->objects.

Currently these are:

EthSyncing
SendTransaction
EstimateTransaction
CallTransaction
Block
Transaction
Receipt
Filter
FilterChange
SHHPost
SHHFilter
SHHFilterChange
SHHMessage

To regenerate run

composer run-script generate-complex-datatypes

Testing

composer install
vendor/bin/phpunit

See phpunit.xml and tests/

Static tests

Based on TestStatic.php

vendor/bin/phpunit --testsuite EthereumPhp

or a single test class

vendor/bin/phpunit --filter {FunctionSignatureTest}

Dynamic tests

You can us this library to test smart contracts in combination with truffle. This are tests based on TestEthClient.php

It requires a running Ethereum node, with the contracts deployed to. The following example uses Truffle and Ganache.

Smart contract test workflow

  • Truffle compile creates a JsonFile in test_contracts/build/CONTRACT-NAME.json
  • TestEthContract base class loads the Json file, so that PHP knows the ethereum address of the contract in the network
  • So for tests based on TestEthContract you have $this->contract available and can call functions. See example.

Prepare contract testing

# Install truffle.
npm -i -g truffle

# Compile contracts
cd ethereum-php/tests/TestEthClient/test_contracts
truffle compile

# Migrate Contracts to the Ganache Test network
truffle migrate

vendor/bin/phpunit --testsuite TestEthClient

You may define NETWORK_ID and SERVER_URL to perform testing against multiple Ethereum clients.

NETWORK_ID='5777' SERVER_URL="http://127.0.0.1:7545" vendor/bin/phpunit

API doc generation

The API documentation is auto-generated by doxygen.

doxygen Doxyfile

There is a online version of this API documentation at http://ethereum-php.org/dev

Doxygen script does some pre processing which requires GNU-sed on OSX brew install gnu-sed --with-default-names See: https://stackoverflow.com/a/27834828/308533

Credits

Many thanks to...

  • ConsenSys for sponsoring the Development of Ethereum-PHP library and Drupal module.
  • kornrunner for implementing a PHP based keccak
  • Nick Dodson and Dan Finlay for their work on ethjs-schema. This API is based on it.
  • Jim Wigginton for the Math_BigInteger pear package.

Ethereum-PHP library is part of the Drupal Ethereum Module.