{"id":43365011,"url":"https://github.com/kodmanyagha/web3php","last_synced_at":"2026-02-02T04:41:51.756Z","repository":{"id":63029556,"uuid":"564668427","full_name":"kodmanyagha/web3php","owner":"kodmanyagha","description":"Ethereum web3 PHP library and other utils (create wallet, send raw tx etc...)","archived":false,"fork":false,"pushed_at":"2023-01-11T11:28:25.000Z","size":176,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-12T13:53:22.863Z","etag":null,"topics":["ethereum","php","web3","web3php"],"latest_commit_sha":null,"homepage":"","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/kodmanyagha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-11-11T08:07:42.000Z","updated_at":"2022-11-11T08:09:49.000Z","dependencies_parsed_at":"2023-02-09T02:45:19.905Z","dependency_job_id":null,"html_url":"https://github.com/kodmanyagha/web3php","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/kodmanyagha/web3php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodmanyagha%2Fweb3php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodmanyagha%2Fweb3php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodmanyagha%2Fweb3php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodmanyagha%2Fweb3php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kodmanyagha","download_url":"https://codeload.github.com/kodmanyagha/web3php/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodmanyagha%2Fweb3php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29005796,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-02T04:25:24.522Z","status":"ssl_error","status_checked_at":"2026-02-02T04:24:51.069Z","response_time":58,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["ethereum","php","web3","web3php"],"created_at":"2026-02-02T04:41:50.757Z","updated_at":"2026-02-02T04:41:51.746Z","avatar_url":"https://github.com/kodmanyagha.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# web3.php\n\n[![PHP](https://github.com/kodmanyagha/web3php/actions/workflows/php.yml/badge.svg)](https://github.com/web3p/web3.php/actions/workflows/php.yml)\n[![Build Status](https://travis-ci.org/kodmanyagha/web3php.svg?branch=master)](https://travis-ci.org/kodmanyagha/web3php)\n[![codecov](https://codecov.io/gh/kodmanyagha/web3php/branch/master/graph/badge.svg)](https://codecov.io/gh/web3p/web3.php)\n[![Join the chat at https://gitter.im/web3-php/web3.php](https://img.shields.io/badge/gitter-join%20chat-brightgreen.svg)](https://gitter.im/kodmanyagha/web3php)\n[![Licensed under the MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/kodmanyagha/web3php/blob/master/LICENSE)\n\n\nA php interface for interacting with the Ethereum blockchain and ecosystem.\n\n# Install\n\nSet minimum stability to dev\n```\n\"minimum-stability\": \"dev\"\n```\n\nThen\n```\ncomposer require kodmanyagha/web3php dev-master\n```\n\nOr you can add this line in composer.json\n\n```\n\"kodmanyagha/web3php\": \"dev-master\"\n```\n\n\n# Usage\n\n### New instance\n```php\nuse Kdm\\Web3;\n\n$web3 = new Web3('http://localhost:8545');\n```\n\n### Using provider\n```php\nuse Kdm\\Web3;\nuse Kdm\\Providers\\HttpProvider;\nuse Kdm\\RequestManagers\\HttpRequestManager;\n\n$web3 = new Web3(new HttpProvider(new HttpRequestManager('http://localhost:8545')));\n\n// timeout\n$web3 = new Web3(new HttpProvider(new HttpRequestManager('http://localhost:8545', 0.1)));\n```\n\n### You can use callback to each rpc call:\n```php\n$web3-\u003eclientVersion(function ($err, $version) {\n    if ($err !== null) {\n        // do something\n        return;\n    }\n    if (isset($version)) {\n        echo 'Client version: ' . $version;\n    }\n});\n```\n\n### Eth\n```php\nuse Kdm\\Web3;\n\n$web3 = new Web3('http://localhost:8545');\n$eth = $web3-\u003eeth;\n```\n\nOr\n\n```php\nuse Kdm\\Eth;\n\n$eth = new Eth('http://localhost:8545');\n```\n\n### Net\n```php\nuse Kdm\\Web3;\n\n$web3 = new Web3('http://localhost:8545');\n$net = $web3-\u003enet;\n```\n\nOr\n\n```php\nuse Kdm\\Net;\n\n$net = new Net('http://localhost:8545');\n```\n\n### Batch\n\nweb3\n```php\n$web3-\u003ebatch(true);\n$web3-\u003eclientVersion();\n$web3-\u003ehash('0x1234');\n$web3-\u003eexecute(function ($err, $data) {\n    if ($err !== null) {\n        // do something\n        // it may throw exception or array of exception depends on error type\n        // connection error: throw exception\n        // json rpc error: array of exception\n        return;\n    }\n    // do something\n});\n```\n\neth\n\n```php\n$eth-\u003ebatch(true);\n$eth-\u003eprotocolVersion();\n$eth-\u003esyncing();\n\n$eth-\u003eprovider-\u003eexecute(function ($err, $data) {\n    if ($err !== null) {\n        // do something\n        return;\n    }\n    // do something\n});\n```\n\nnet\n```php\n$net-\u003ebatch(true);\n$net-\u003eversion();\n$net-\u003elistening();\n\n$net-\u003eprovider-\u003eexecute(function ($err, $data) {\n    if ($err !== null) {\n        // do something\n        return;\n    }\n    // do something\n});\n```\n\npersonal\n```php\n$personal-\u003ebatch(true);\n$personal-\u003elistAccounts();\n$personal-\u003enewAccount('123456');\n\n$personal-\u003eprovider-\u003eexecute(function ($err, $data) {\n    if ($err !== null) {\n        // do something\n        return;\n    }\n    // do something\n});\n```\n\n### Contract\n\n```php\nuse Kdm\\Contract;\n\n$contract = new Contract('http://localhost:8545', $abi);\n\n// deploy contract\n$contract-\u003ebytecode($bytecode)-\u003enew($params, $callback);\n\n// call contract function\n$contract-\u003eat($contractAddress)-\u003ecall($functionName, $params, $callback);\n\n// change function state\n$contract-\u003eat($contractAddress)-\u003esend($functionName, $params, $callback);\n\n// estimate deploy contract gas\n$contract-\u003ebytecode($bytecode)-\u003eestimateGas($params, $callback);\n\n// estimate function gas\n$contract-\u003eat($contractAddress)-\u003eestimateGas($functionName, $params, $callback);\n\n// get constructor data\n$constructorData = $contract-\u003ebytecode($bytecode)-\u003egetData($params);\n\n// get function data\n$functionData = $contract-\u003eat($contractAddress)-\u003egetData($functionName, $params);\n```\n\n# Assign value to outside scope(from callback scope to outside scope)\nDue to callback is not like javascript callback, \nif we need to assign value to outside scope, \nwe need to assign reference to callback.\n```php\n$newAccount = '';\n\n$web3-\u003epersonal-\u003enewAccount('123456', function ($err, $account) use (\u0026$newAccount) {\n    if ($err !== null) {\n        echo 'Error: ' . $err-\u003egetMessage();\n        return;\n    }\n    $newAccount = $account;\n    echo 'New account: ' . $account . PHP_EOL;\n});\n```\n\n# Examples\n\nTo run examples, you need to run ethereum blockchain local (testrpc).\n\nIf you are using docker as development machain, you can try [ethdock](https://github.com/sc0vu/ethdock) to run local ethereum blockchain, just simply run `docker-compose up -d testrpc` and expose the `8545` port.\n\n# Develop\n\n### Local php cli installed\n\n1. Clone the repo and install packages.\n```\ngit clone https://github.com/web3p/web3.php.git \u0026\u0026 cd web3.php \u0026\u0026 composer install\n```\n\n2. Run test script.\n```\nvendor/bin/phpunit\n```\n\n### Docker container\n\n1. Clone the repo and run docker container.\n```\ngit clone https://github.com/web3p/web3.php.git\n```\n\n2. Copy web3php to web3php/docker/app directory and start container.\n```\ncp files docker/app \u0026\u0026 docker-compose up -d php ganache\n```\n\n3. Enter php container and install packages.\n```\ndocker-compose exec php ash\n```\n\n4. Change testHost in `TestCase.php`\n```\n/**\n * testHost\n * \n * @var string\n */\nprotected $testHost = 'http://ganache:8545';\n```\n\n5. Run test script\n```\nvendor/bin/phpunit\n```\n\n###### Install packages\nEnter container first\n```\ndocker-compose exec php ash\n```\n\n1. gmp\n```\napk add gmp-dev\ndocker-php-ext-install gmp\n```\n\n2. bcmath\n```\ndocker-php-ext-install bcmath\n```\n\n3openssl\n```\ndocker-php-ext-install openssl\n```\n\n###### Remove extension\nMove the extension config from `/usr/local/etc/php/conf.d/`\n```\nmv /usr/local/etc/php/conf.d/extension-config-name to/directory\n```\n\n\n# License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkodmanyagha%2Fweb3php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkodmanyagha%2Fweb3php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkodmanyagha%2Fweb3php/lists"}