I wrote a contract that get a unit and do something

My question :

How to pass a value to this contract function via PHP? (not js,py,MetaMask, ... . just in php)

For example, I use this and install success in my Ubuntu server and run

geth account new

and get the result.

But I don't know how to use next step (Developer/Management API).

Please describe a real example by details with any packages or something that familer for you from how to install package on Ubuntu server and a simple contract that get a value and write a PHP file that if I run in my Lampp, send a value to my contract

I saw a lot of same question in google, but most of them done with js or in short form in PHP and I cant figure out

I'm new in use GitHub and Composer.JSON files


Welcome to SE! Check out the https://github.com/sc0Vu/web3.php project.

Their examples can help you out in achieving this in PHP.

// example
use Web3\Contract;

$contractABI = '[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"}]';

$contract = new Contract('http://localhost:8545', $contractABI);

$contractAddress = "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2";

// call contract function
$contract->at($contractAddress)->call("name", null, function($data) {
    echo "received name" + $data;

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.