2

how I use to users to send ethereum transactions through a php website?My server is Apache. Is the Ethereum JavaScript API useful to doing this? Thank you!

  • Hi, can you please clarify what you mean by "how I use to users"? I see other people have answered, but I'm still not sure what the question is! – lungj Aug 4 '17 at 14:23
1

You can use below steps for the same:

1) Use web3 API to communicate with blockchain.

Add web3 CDN to your index file.

Check web3 documentation to connect blockchain and for other actions

2) Use XMLHttpRequest() or direct AJAX call to communicate between javascript and PHP.

var web3 = new Web3(new 
Web3.providers.HttpProvider("http://localhost:8545"));  
var abi = [{<ABI>}];
var myContract = web3.eth.contract(abi);
var contractInstance = myContract.at(<account address>);
val = contractInstance.<contract-method>.call();

$.ajax({
    type: 'post',
    url: 'test.php',
    data: val
});

Hope this helps..!

  • Please provide me step by step detail to use it. – user16572 Aug 4 '17 at 6:53
0

可以!我现在就是这么做的 (You can! I'm doing that now)

    <?php

/**
 * Ethereum JSON-RPC interface
 *
 * See Ethereum API documentation for more information:
 * http://ethereum.gitbooks.io/frontier-guide/content/rpc.html
 */

require_once(dirname(__FILE__).'/json-rpc.php');

class Ethereum extends JSON_RPC
{
    private function ether_request($method, $params=array())
    {
        try 
        {
            $ret = $this->request($method, $params);
            return $ret->result;
        }
        catch(RPCException $e) 
        {
            throw $e;
        }
    }

    private function decode_hex($input)
    {
        if(substr($input, 0, 2) == '0x')
            $input = substr($input, 2);

        if(preg_match('/[a-f0-9]+/', $input))
            return hexdec($input);

        return $input;
    }

    function web3_clientVersion()
    {

通过api 直接调用 geth ,我有demo ,不知道怎么发给你 ^_^

(Through the api direct call geth, I have demo, do not know how to send you ^ _ ^)

The documentation for JSON-RPC calls are here.

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