{"id":14985417,"url":"https://github.com/evias/nem-php","last_synced_at":"2025-04-11T15:31:34.541Z","repository":{"id":16943508,"uuid":"80902864","full_name":"evias/nem-php","owner":"evias","description":"NEM Blockchain NIS API Wrapper and Software Development Kit for PHP","archived":false,"fork":false,"pushed_at":"2022-03-29T09:27:40.000Z","size":557,"stargazers_count":33,"open_issues_count":4,"forks_count":18,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-25T15:33:49.771Z","etag":null,"topics":["api-wrapper","composer","laravel","nem","nem-blockchain","php","travis-ci"],"latest_commit_sha":null,"homepage":"https://docs.nem.io","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evias.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-04T07:38:15.000Z","updated_at":"2023-07-22T01:26:03.000Z","dependencies_parsed_at":"2022-08-07T08:15:41.465Z","dependency_job_id":null,"html_url":"https://github.com/evias/nem-php","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evias%2Fnem-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evias%2Fnem-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evias%2Fnem-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evias%2Fnem-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evias","download_url":"https://codeload.github.com/evias/nem-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248431471,"owners_count":21102205,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-wrapper","composer","laravel","nem","nem-blockchain","php","travis-ci"],"created_at":"2024-09-24T14:10:56.496Z","updated_at":"2025-04-11T15:31:30.020Z","avatar_url":"https://github.com/evias.png","language":"PHP","readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"https://nem.io/wp-content/themes/nem/img/logo-nem.svg\" width=\"400\"\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://travis-ci.org/evias/nem-php\"\u003e\u003cimg src=\"https://travis-ci.org/evias/nem-php.svg\" alt=\"Build Status\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/evias/nem-php\"\u003e\u003cimg src=\"https://poser.pugx.org/evias/nem-php/d/total.svg\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/evias/nem-php\"\u003e\u003cimg src=\"https://poser.pugx.org/evias/nem-php/v/stable.svg\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/evias/nem-php\"\u003e\u003cimg src=\"https://poser.pugx.org/evias/nem-php/v/unstable\" alt=\"Latest Unstable Version\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/evias/nem-php\"\u003e\u003cimg src=\"https://poser.pugx.org/evias/nem-php/license.svg\" alt=\"License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nThis package aims to provide with an easy-to-use PHP Laravel Namespace helping developers to communicate with the NEM blockchain through its NIS API.\n\nThis package should be an aid to any developer working on Laravel/Lumen/Symfony applications with the NEM blockchain.\n\n**This package is currently still in development, please do not use in production.**\n\n*The author of this package cannot be held responsible for any loss of money or any malintentioned usage forms of this package. Please use this package with caution.*\n\nPackage licensed under [MIT](LICENSE) License.\n\n## Documentation\n\nReader-friendly Documentation will be added in development period and will be available on the Github Wiki at [evias/nem-php Wiki](https://github.com/evias/nem-php/wiki).\n\nCurrently phpdocumentor is integrated to the project in order to automatically generate API documentation from the source code. You must run the `phpdoc` and `phpdocmd` command if you wish to generate the Documentation, the first stable release will include a generated Documentation version.\n\n```bash\n# First build the API documentation\n./vendor/bin/phpdoc -d src/ -t build/ --template=\"xml\"\n\n# Then generate the Markdown\n./vendor/bin/phpdocmd build/structure.xml docs/\n```\n\n## Pot de vin\n\nIf you like the initiative, and for the sake of good mood, I recommend you take a few minutes to Donate a beer or Three [because belgians like that] by sending some XEM (or whatever Mosaic you think pays me a few beers someday!) to my Wallet:\n\n    NB72EM6TTSX72O47T3GQFL345AB5WYKIDODKPPYW\n\n| Username | Role |\n| --- | --- |\n| [eVias](https://github.com/evias) | Project Lead |\n| [RobertoSnap](https://github.com/RobertoSnap) | Developer |\n\n## Installation\n\nYou can install this package with Composer. You only need to require evias/nem-php.\n\n```bash\ncomposer require evias/nem-php\n```\n\nThe package can also be downloaded manually by cloning this repository or by downloading the packagist archive:\n\n- [nem-php at Packagist](https://packagist.org/packages/evias/nem-php)\n- [nem-php at Github](https://github.com/evias/nem-php)\n- [ZIP Archive of master branch at Github](https://github.com/evias/nem-php/archive/master.zip)\n- [nem-php Releases at Github](https://github.com/evias/nem-php/releases)\n\nOnce you have required the package in your `composer.json` file (or using the command above), you can install\nthe dependencies of this package:\n\n```bash\ncomposer install\n```\n\n## Unit Tests\n\nThe library provides with a Unit Test Suite for the implemented SDK features.\n\nThe unit test suite is also configured on Travis-CI with the current Build Status:\n\n- [![Build Status](https://api.travis-ci.org/evias/nem-php.svg?branch=master)](https://travis-ci.com/evias/nem-php)\n\nIf you wish to run the unitary test suite, you can use the executable file provided by PHPUnit which is located\nunder `vendor/bin/phpunit`.\n\nAlernatively, you can create a symbolic link to this executable file in the `nem-php` clone root folder.\n\n```bash\nln -s vendor/bin/phpunit \n```\n\nNow you can simply run `phpunit` in the terminal and it will launch the Rocket.. meh, the Unit Tests Suite.\n\n### Laravel advanced features\n\nModify your `config/app.php` configuration file to include the NEM\\ServiceProvider service provider. Look out\nfor the **providers** configuration array and add our class as shown below:\n\n```php\n'providers' =\u003e [\n    NEM\\ServiceProvider::class,\n],\n```\n\nIf you wish to make use of the Laravel Facades provided by this library, you will also need to list the alias\nin your `config/app.php` configuration file under the **aliases** configuration array as described below:\n\n```php\n'aliases' =\u003e [\n    'NemSDK' =\u003e NEM\\Facades\\NemSDK::class,\n],\n```\n\n## Usage / Examples\n\nWhen you have installed the evias/nem-php package you will be able to use the API class to send API requests to the configured NIS. By default, the config/nem.php file defines the localhost NIS to be used, this can be changed.\n\nIf you are using Laravel or Lumen, you will need to register the Service Provider of this package into your app:\n\n```php\n    // Laravel/Lumen registering the service provider\n    $app = Laravel\\Lumen\\Application(realpath(__DIR__));\n    $app-\u003eregister(NEM\\ServiceProvider::class);\n```\n\n### Example 1: Using the Service Provider (Laravel only)\n\n```php\n    // Example 1: Using the Service Provider\n    // --------------------------------------\n    // The Service Provider for Laravel/Lumen will bind \"nem.config\",\n    // \"nem\" and \"nem.ncc\" in the IoC. \"nem\" and \"nem.ncc\" are pre-\n    // configured instances of the API class using APP_ENV for the environment.\n    $nemConfig = $app[\"nem.config\"]\n    $nemAPI = $app[\"nem\"];\n    $nccAPI = $app[\"nem.ncc\"];\n```\n\n### Example 2: Using the API wrapper\n\n```php\n    // Example 2: Instantiating the API class\n    // --------------------------------------\n    // You can also create a new instance of the API\n    $nemAPI = new NEM\\API();\n    $nemAPI-\u003esetOptions([\n        \"protocol\" =\u003e \"http\",\n        \"use_ssl\" =\u003e false,\n        \"host\" \t  =\u003e \"go.nem.ninja\",\n        \"port\"    =\u003e 7890,\n        \"endpoint\" =\u003e \"/\",\n    ]);\n\n    // If you wish you can define your own RequestHandler, have a look at the\n    // NEM\\Contracts\\RequestHandler interface.\n    $nemAPI-\u003esetOptions([\"handler_class\" =\u003e Path\\To\\My\\Handler::class]);\n```\n\n### Example 3: Sending GET/POST request to the NIS API and getting back JSON\n\n```php\n    // Example 3: Sending GET/POST JSON requests\n    // -----------------------------------------\n    // The API wrapper class can be used to send API requests to the\n    // configured NIS host with following snippet:\n    $response = $nemAPI-\u003egetJSON(\"heartbeat\", \"\");\n\n    // sending JSON through POST and receiving JSON back.\n    $postData = [\"myField\" =\u003e \"hasThisValue\", \"yourField\" =\u003e \"isNotEmpty\"];\n    $response = $nemAPI-\u003epostJSON(\"post/endpoint\", json_encode($postData));\n```\n\n### Example 4: Custom Headers and response callback configurations\n\n```php\n    // Example 4: Custom headers and Callback configuration\n    // -----------------------------------------------------\n    // The 3rd parameter of the get() and post() methods lets you pass\n    // an options array to the RequestHandler. To add specific headers for\n    // example you would do as follows:\n    $response = $nemAPI-\u003egetJSON(\"hearbeat\", \"\", [\"headers\" =\u003e [\"Content-Type\" =\u003e \"text/xml\"]]);\n\n    // You may also define onSuccess, onError and onReject callbacks to be executed\n    // when the Guzzle Promises respectively complete, encounter an error or are denied.\n    // @see Psr\\Http\\Message\\ResponseInterface\n    // @see GuzzleHttp\\Exception\\RequestException\n    $response = $nemAPI-\u003egetJSON(\"heartbeat\", \"\", [\n        \"onSuccess\" =\u003e function(ResponseInterface $response) {\n            echo $response-\u003egetBody();\n        },\n        \"onError\" =\u003e function(RequestException $exception) {\n            echo \"This is bad: \" . $exception-\u003egetMessage();\n        },\n        \"onReject\" =\u003e function($reason) {\n            echo \"Request could not be completed: \" . $reason;\n        }\n    ]);\n```\n\n### Example 5: Use the SDK to create NEM *NIS compliant* Objects\n\n```php\n    // Example 5: Use the SDK to create NEM *NIS compliant* Objects\n    // ------------------------------------------------------------\n    // You can create an instance and pass the *connection configuration*\n    $sdk = new NEM\\SDK([\n        \"protocol\" =\u003e \"http\",\n        \"use_ssl\" =\u003e false,\n        \"host\" \t  =\u003e \"go.nem.ninja\",\n        \"port\"    =\u003e 7890,\n        \"endpoint\" =\u003e \"/\",\n    ]);\n\n    // Or you can use an already initialized API client\n    $sdk = new NEM\\SDK([], new NEM\\API());\n    $account = $sdk-\u003emodels()-\u003eaccount([\"address\" =\u003e \"TDWZ55R5VIHSH5WWK6CEGAIP7D35XVFZ3RU2S5UQ\"]);\n\n    // The \\NEM\\Contracts\\DataTransferObject interface tells us that Models\n    // always have a toDTO() method which will format the said object into\n    // its *NIS compliant* object.\n\n    // Dump [AccountMetaDataPair](https://bob.nem.ninja/docs/#accountMetaDataPair) object\n    var_dump($account-\u003etoDTO());\n```\n\n### Example 6: Use the SDK NIS Web Service implementations\n\n```php\n    // Example 6: Use the SDK NIS Web Service implementations\n    // ------------------------------------------------------------\n    $sdk = new NEM\\SDK();\n    $service = $sdk-\u003eaccount();\n\n    // Generate a new account\n    $account = $service-\u003egenerateAccount(); // $account is an instance of \\NEM\\Models\\Account\n\n    // Read account data *from the NEM blockchain* using the Address\n    $account = $service-\u003egetFromAddress(\"TDWZ55R5VIHSH5WWK6CEGAIP7D35XVFZ3RU2S5UQ\");\n\n    // Read account data *from the NEM blockchain* using the Public Key\n    $account = $service-\u003egetFromPublicKey(\"d90c08cfbbf918d9304ddd45f6432564c390a5facff3df17ed5c096c4ccf0d04\");\n```\n\n### Example 7: Use the SDK to read an account's transactions\n\n```php\n    // Example 7: Use the SDK to read an account's transactions\n    // ------------------------------------------------------------\n    $sdk = new NEM\\SDK();\n    $service = $sdk-\u003eaccount();\n\n    // Get incoming transaction for an account by its address\n    // $incomings will be an instance of \\NEM\\Models\\ModelCollection\n    $incomings = $service-\u003eincomingTransactions(\"TDWZ55R5VIHSH5WWK6CEGAIP7D35XVFZ3RU2S5UQ\");\n\n    // Get outgoing transaction for an account by its address\n    $outgoings = $service-\u003eoutgoingTransactions(\"TDWZ55R5VIHSH5WWK6CEGAIP7D35XVFZ3RU2S5UQ\");\n\n    // Get unconfirmed transaction for an account by its address\n    $unconfirmed = $service-\u003eunconfirmedTransactions(\"TDWZ55R5VIHSH5WWK6CEGAIP7D35XVFZ3RU2S5UQ\");\n```\n\n### Example 8: Derive a Public Key with a hexadecimal or binary Private Key\n\n```php\n    // Example 8: Derive a Public Key with a hexadecimal or binary Private Key\n    // --------------------------------------------------------------------------\n    $privateKey = \"e77c84331edbfa3d209c4e68809c98a634ad6e8891e4174455c33be9dd25fce5\";\n    $publicKey  = \"d90c08cfbbf918d9304ddd45f6432564c390a5facff3df17ed5c096c4ccf0d04\";\n    $keypair = new NEM\\Core\\KeyPair($privateKey);\n    var_dump($keypair-\u003egetPublicKey(\"hex\")); // will output: \n\n    // Create with *provided public key* (no derivation - faster)\n    $keypair = new NEM\\Core\\KeyPair($privateKey, $publicKey);\n```\n\n### Example 9: Create New KeyPair and Address (randomly)\n\n```php\n    // Example 9: Create New KeyPair and Address (randomly)\n    // --------------------------------------------------------------------------\n    $keypair = new NEM\\Core\\KeyPair();\n    $address = NEM\\Models\\Address::fromPublicKey($keypair-\u003egetPublicKey());\n\n    var_dump($keypair-\u003egetPrivateKey(\"hex\"), $address-\u003etoClean());\n```\n\n### Example 10: Sign Data with a NEM KeyPair\n\n```php\n    // Example 10: Sign Data with a NEM KeyPair\n    // --------------------------------------------------------------------------\n    $keypair = new NEM\\Core\\KeyPair(\"abf4cf55a2b3f742d7543d9cc17f50447b969e6e06f5ea9195d428ab12b7318d\");\n\n    var_dump($keypair-\u003esign(\"nem-php by eVias!\")-\u003egetHex());\n    // this will show you the following hexadecimal signature:\n    // 177908f0cb5e56a0da11bfc3b38f6d749c4c870c9b356313db6460925e4584a9304e6aa1a5ba50ec2f773bbdfbfc03285a35d986d056df27b7d05a74f6c9b501\n\n    // you can now use this signature and verify it using the Public Key\n```\n\n## Troubleshoot / Issues Resolution\n\n### Installing dependencies with MacOS MAMP or MAMP Pro\n\nIt may happen that your PHP server is not installed in the correct version or does not load the right extensions so here is a little snippet that will provide you with the exact PHP version needed (you also need to compile httpd).\n\nFirst you will need to rebuilt the httpd service :\n\n```bash\nmkdir ~/httpd-2.2.34/\n\n# Download httpd source code\ncd ~/Downloads\nwgets http://apache.belnet.be//httpd/httpd-2.2.34.tar.bz2\ntar xvzf httpd-2.2.34.tar.bz2\n\n# We now have the HTTPD source code unarchived\ncd httpd-2.2.34\n./configure\nmake\nmake install\n```\n\nThe above step is only because MAMP does not include the Apache build/ folder (which you can now find under `~/httpd-2.2.34/`). Ok, next step is to recompile PHP *as an Apache Module* as required by MAMP. Following snippet will let you download and compile the PHP package with MacOS and MAMP, enabling GMP, GD, MySQL, XML, CURL, GETTEXT, MBSTRING and BCMATH modules.\n\n```bash\n# This is where the *built* PHP will be installed.\nmkdir ~/php-7.1.8/\n\n# Download php source code\ncd ~/Downloads\nwgets http://de2.php.net/get/php-7.1.8.tar.bz2/from/this/mirror\ntar xvzf php-7.1.8.tar.bz2\n\n# We now have the PHP source code unarchived\ncd php-7.1.8\n\n# MacOS\nbrew install intltool icu4c gettext\nbrew link icu4c gettext\n./configure --with-apxs2=/Applications/MAMP/Library/bin/apxs --prefix=/Users/greg/php-7.1.8 --enable-intl --with-gmp --with-xmlrpc --enable-bcmath --with-curl=/usr --with-gettext=/usr/local/Cellar/gettext/ --with-gd --with-pdo-mysql --with-openssl=/usr/local/Cellar/openssl/1.0.2n/ --enable-mbstring\nmake\nmake install\n# End-MacOS\n\n# Linux\n./configure --prefix=/home/greg/php-7.1.8 --enable-intl --with-gmp --with-xmlrpc --enable-bcmath --with-curl=/usr --with-gettext --with-gd --with-pdo-mysql --with-openssl\nmake\nmake install\n# End-Linux\n```\n\nAfter building the PHP source code you will also need to link to that file in your system. Following is an easy workaround, but *please*, make sure to backup any file before you overwrite executables.\n\nThe compilation of PHP will have installed a file: `~/httpd-2.2.34/modules/libphp7.so`, you must link your system to that file in order to use the correct PHP modules. Use following snippet to link both, the PHP apache module and the PHP executable in your MAMP installation.\n\n```bash\nmkdir /Applications/MAMP/Library/build\ncp -R /Users/greg/httpd-2.2.34/build/* /Applications/MAMP/Library/build/\nsudo ln -s /Users/greg/httpd-2.2.34/modules/libphp7.so /Applications/MAMP/bin/php/php7.1.8/modules/\nsudo ln -s /Users/greg/php-7.1.8/bin/php /usr/local/bin/php\n```\n\n## Changelog\n\nImportant versions listed below. Refer to the [Changelog](CHANGELOG.md) for a full history of the project.\n\n- [1.0.0](CHANGELOG.md#v100) - revamp of the SDK\n- [0.0.3](CHANGELOG.md#v003) - ongoing development\n- [0.0.2](CHANGELOG.md#v002) - 2017-02-18\n- [0.0.1](CHANGELOG.md#v001) - 2017-02-04\n\n## License\n\nThis software is released under the [MIT](LICENSE) License.\n\n© 2017-2018 Grégory Saive \u003cgreg@evias.be\u003e, All rights reserved.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevias%2Fnem-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevias%2Fnem-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevias%2Fnem-php/lists"}