Giter Site home page Giter Site logo

digitaldonkey / ethereum-php Goto Github PK

View Code? Open in Web Editor NEW
487.0 487.0 172.0 1.96 MB

PHP interface to Ethereum JSON-RPC API. Fully typed Web3 for PHP 7.X

Home Page: http://ethereum-php.org

License: MIT License

PHP 95.95% CSS 0.49% HTML 0.98% JavaScript 0.29% Shell 0.08% Solidity 2.21%
ethereum ethereum-client ethereum-php ethereum-php-library php php-interface smart-contracts web3 web3-php web3php

ethereum-php's Introduction

Ethereum-PHP

is a typed PHP-7.1+ interface to Ethereum JSON-RPC API.

Check out the latest API documentation.

Add library in a composer.json file

{
  "minimum-stability":"dev",
  "autoload": {
    "psr-4": {
      "Ethereum\\": "src/"
    }
  },
  "repositories": [
    {
      "type": "git",
      "url": "https://github.com/digitaldonkey/ethereum-php.git"
    }
  ],
  "require": {
    "digitaldonkey/ethereum-php": "dev-master"
  }
}

Usage

composer require digitaldonkey/ethereum-php

This is the important part of composer.json in Drupal Ethereum Module.

require __DIR__ . '/vendor/autoload.php';
use Ethereum\Ethereum;

try {
	// Connect to Ganache
    $eth = new Ethereum('http://127.0.0.1:7545');
    // Should return Int 63
    echo $eth->eth_protocolVersion()->val();
}
catch (\Exception $exception) {
    die ("Unable to connect.");
}

Calling Contracts

You can call (unpayed) functions in smart contracts easily.

The json file "$fileName" used is what you get when you compile a contract with Truffle.

$ContractMeta = json_decode(file_get_contents($fileName));
$contract = new SmartContract(
  $ContractMeta->abi,
  $ContractMeta->networks->{NETWORK_ID}->address,
  new Ethereum(SERVER_URL)
);
$someBytes = new EthBytes('34537ce3a455db6b')
$x = $contract->myContractMethod();
echo $x->val()

You can also run tests at smart contracts, check out EthTestClient.

Event listening and handling

You can use Ethereum-PHP to watch changed on your smart contracts or index a Blockchain block by block. gs

See UsingFilters and ethereum-php-eventlistener.

Limitations

Currently not all datatypes are supported.

This library is read-only for now. This means you can retrieve information stored in Ethereum Blockchain.

To write to the blockchain you need a to sign transactions with a private key which is not supported yet.

architecture diagram

Documentation

The API documentation is available at ethereum-php.org.

For reference see the Ethereum RPC documentation and for data encoding RLP dcumentation in Ethereum Wiki.

There is also a more readable Ethereum Frontier Guide version.

ethereum-php's People

Contributors

andsol avatar antohaby avatar beycandeveloper avatar cryt1c avatar digitaldonkey avatar owenvoke avatar sebnyc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ethereum-php's Issues

Exception on eth_getTransactionReceipt

When a transaction receipt has a log array that includes a data value of "0x", it triggers an exception

Try with :
$tr = $eth->eth_getTransactionReceipt(new EthD32("0xee04d9e2258909ca642acde0612597732f4ba244952e23eb83ecac3fe8dd5091"));

You should get this exception :
InvalidArgumentException : Value of dynamic ABI type is not a valid hex string.

at /var/www/vendor/digitaldonkey/ethereum-php/src/DataType/EthBytes.php:36
32| */
33| public function validate($val, array $params)
34| {
35| if (!ctype_xdigit($this->removeHexPrefix($val))) {
36| throw new \InvalidArgumentException(
37| 'Value of dynamic ABI type is not a valid hex string.'
38| );
39| }
40| return $this->ensureHexPrefix($val);

Exception trace:

1 Ethereum\DataType\EthBytes::validate("0x", [])
/var/www/vendor/digitaldonkey/ethereum-php/src/DataType/EthDataType.php:239

2 Ethereum\DataType\EthDataType::setValue("0x", [])
/var/www/vendor/digitaldonkey/ethereum-php/src/DataType/EthD.php:145

3 Ethereum\DataType\EthD::__construct("0x")
/var/www/vendor/digitaldonkey/ethereum-php/src/Ethereum.php:522

4 Ethereum\Ethereum::arrayToComplexType("\Ethereum\DataType\FilterChange")
/var/www/vendor/digitaldonkey/ethereum-php/src/Ethereum.php:513

5 Ethereum\Ethereum::arrayToComplexType("\Ethereum\DataType\Receipt")
/var/www/vendor/digitaldonkey/ethereum-php/src/Ethereum.php:284
...

Unexpected negative quantity for transactions

When reading transactions in the blockchain, it appears that some "value" fields of transactions are decoded as negative, whereas this data is supposed to be positive.

I see in the code that you are aware of the problem in \Ethereum\DataType\EthQ::validate()
// @todo This might be wrong. We need to check for RLP.
// @see https://github.com/ethereum/wiki/wiki/RLP

Is this project currently maintained?

  1. Is this project currently maintained?
  2. Do I have to open any additional ports on my Linux server?
  3. Can I use this API to add transactions to the Ropsten Testnet?

About php version 7.2

When I tried to composer install this package, it came out an error that said the package requires php >= 7.2, which the composer.json file shows. But the README.md says all php version 7.1+ satisfy the requirement. Do I have to upgrade my php version to 7.2+? Or can you just lower the php version requirement.

[Question] Is possible to generate new account offline

Hi guys, how's going?

I very new on the blockchain, ethereum, all that stuff, and I have some sort of an "issue".

I saw a lot of libraries to work with ethereum in PHP and basically, all of them needs a connection with some ethereum network to work. But I noticed a lot of that networks as a service they don't allow us to create address/wallet/account due to security issues.

So there any way that I can generate those address offline? I saw this post and it seems possible to create offline.

I was thinking to add that feature. As an optional param to generate offline. We still will be needing a network to connect into, but that address part will be optional, with the default value as 'false'. If the network allows you to create, that one already works. If not allows, just change to 'true'.

What do you guys think?

Sorry if I said something wrong. Still learning.

Kind regards.

Amandio.

Unable to retrieve transactions array of a block

While trying to retrieve the transaction array of a block, I get an error "Call to undefined method Ethereum\DataType\Transaction::val()" in \DataType\EthDataType.php:199 Stack trace: #0

$tx_data = $block_latest->getProperty('transactions');

Any help would be appreciated.

FatalThrowableError: Call to undefined method Ethereum\Filter::getType()

digitaldonkey/ethereum-php/src/Ethereum.php on line 98

$filter = new Filter(
            null,
            new EthBlockParam(),
            new EthData('contract_address'),
            [
                new EthData('0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'),
                null,
                new EthData($account)
            ]
        );

        return $this->ok([
            'logs' => $this->client->eth_getLogs($filter)
        ]);

Create Wallet

Do you know how to create a private and public key in php?

How to make encode with uint256[10] in php

I have file json with method name addTransaction,please help me with encodeFunction
data abi.json :
[ {
"constant": false,
"inputs": [
{
"internalType": "string",
"name": "_uid",
"type": "string"
},
{
"internalType": "string",
"name": "_username",
"type": "string"
},
{
"internalType": "string",
"name": "_ref_by",
"type": "string"
},
{
"internalType": "uint256",
"name": "_amount",
"type": "uint256"
},
{
"internalType": "string",
"name": "_merchant",
"type": "string"
},
{
"internalType": "string",
"name": "_subid",
"type": "string"
},
{
"internalType": "uint256",
"name": "_release",
"type": "uint256"
},
{
"internalType": "uint256[10]",
"name": "_ref_rates",
"type": "uint256[10]"
}
],
"name": "addTransaction",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
} ]

Need Help For ERC-721

Hi sir do u have a repo of creating a NFT using php , if u have kindly provide, Thank you !

i have a error when i use ethereum-php-eventlistener

PHP Fatal error: Uncaught Exception: Graze\GuzzleHttp\JsonRpc\Exception\ClientException: Client RPC error response [uri] / [method] eth_getBlockByNumber [error code] -32602 [error message] invalid argument 0: hex number with leading zero digits

this is my temporary solution that change the DataType/EthBlockParam.php. Can you fix this problem๏ผŸ
public function hexVal()
{
if ($this->isTag()) {
return $this->value;
} else {
$val = intval($this->value->toString());
$val = ($val === 0) ? $val : $this->value->toHex(false);
$pattern = "/([0]*)([0-9a-f]+)/i";
$replacement = "$2";
$val = preg_replace($pattern,$replacement,$val);
// Unpaded positive Hex value.
return $this->ensureHexPrefix($val);
}
}

[Question] process log from another contract

Hello !

I'm trying to register events triggered by a contract to another contract. Basically it would like to register ERC721 transfer generated by a linked contract

 public function processLog(FilterChange $filterChange) {

if ($filterChange->address->hexVal() !== $this->contractAddress) {
            return null;
       }

 if (is_array($filterChange->topics)) {
            $topic = $filterChange->topics[0]->hexVal();
            if (isset($this->events[$topic])) { //todo investigate here
                $transaction = $this->eth->eth_getTransactionByHash($filterChange->transactionHash);
                // We have a relevant event.
                $event = new EmittedEvent($this->events[$topic], $filterChange, $transaction);
                // Process onEventName handler.
                if (method_exists($this, $event->getHandler())) {
                    call_user_func([$this, $event->getHandler()], $event);
                }
                return $event;
            }
        }
        return null;
    }

I changed this method to inject tracked contracts list on order to delegate the call process log

This way

  public function processLog(FilterChange $filterChange, $otherTrackedContracts = null) {

        if ($filterChange->address->hexVal() !== $this->contractAddress) {

            if (isset($otherTrackedContracts[$filterChange->address->hexVal()])){
                $matchingContract = $otherTrackedContracts[$filterChange->address->hexVal()];
                return $matchingContract->processLog($filterChange);

            }
            return null;
        }

        if (is_array($filterChange->topics)) {
            $topic = $filterChange->topics[0]->hexVal();
            if (isset($this->events[$topic])) { //todo investigate here
                $transaction = $this->eth->eth_getTransactionByHash($filterChange->transactionHash);
                // We have a relevant event.
                $event = new EmittedEvent($this->events[$topic], $filterChange, $transaction);
                // Process onEventName handler.
                if (method_exists($this, $event->getHandler())) {
                    call_user_func([$this, $event->getHandler()], $event);
                }
                return $event;
            }
        }
        return null;
    }

Is there a better way ? Running this code I'm getting an issue later processing other events while parsing the ABI.
Not sure it's related but I wonder if this this hack is the cause.

Thanks
Shaban

Cannot unmarshal hex number with leading zero digits into Go struct field

Example response from Eth: Client RPC error response [uri] / [method] eth_estimateGas [error code] -32602 [error message] invalid argument 0: json: cannot unmarshal hex number with leading zero digits into Go struct field CallArgs.value of type *hexutil.Big
Method EthQ::hexValUnpadded() must return a string without leading zeros. For example, 0.2 ether (200000000000000000 wei) should be converted to 0x2c68af0bb140000 instead of 0x02c68af0bb140000.

Suggesting changes:

--- src/DataType/EthQ.php
+++ src/DataType/EthQ.php
@@ -282,7 +282,7 @@ class EthQ extends EthD
      */
     public function hexValUnpadded()
     {
-        return '0x' . $this->value->toHex($this->value->is_negative);
+        return '0x' . ltrim($this->value->toHex($this->value->is_negative), '0');
     }

Decode transaction input field

I'm starting to use your library, it looks fantastic.
I would like to decode the 'input' field of transactions, using the ABI of the involved contract (especially for ERC20 contracts). Is there a built-in method to do so ?

function eth_workaround_eth_coinbase($val)

Hi @digitaldonkey ,

thanks for providing this interface and also the drupal/ethereum module!
I would like to contribute to this project too.
Currently I try to get the dev branch running on my environment but I have a problem, when I use the INFURA net because eth_coinbase is not supported by them.
I have found these workaround:

{
    // WORKAROUND: Catch a "405 Method Not Allowed'.
    if (isset($val['error']) && $val['error'] && $val['code'] == 405) {
        return '0x0000000000000000000000000000000000000000';
    } else {
        return $val;
    }
}

But as I see it they are not used at the moment, which breaks the drupal/ethereum module because ethereum-php throws an Exception which is not caught (Expected EthD20 at eth_coinbase (), couldn not be decoded. Value was: Array).
Where should this workaround be used? Can I help you with this? Would be happy to create a PR if you could point me into the right direction.

Thanks for your work!

Expected EthB at eth_syncing (), couldn not be decoded. Value was: Array ( [currentBlock] => 0x3e3d94 [highestBlock] => 0x4d982d [knownStates] => 0x920f [pulledStates] => 0x5ecb [startingBlock] => 0x3e2db4 )

I cloned dev branch into public html and installed dependencies through composer. I want to to use this project to interact with my php7 website and a go-ethereum node running on amazon linux ec2-instance. I can interact with that using geth console and curl function in the terminal.

When I run ethereum-php/public/client-example.php, I get below error in browser. I have my node up and running at 127.0.0.1:8545. I tried with 127.0.0.1 instead if localhost also. But same error. Please help.

We have a problem:
Expected EthB at eth_syncing (), couldn not be decoded. Value was: Array ( [currentBlock] => 0x3e3d94 [highestBlock] => 0x4d982d [knownStates] => 0x920f [pulledStates] => 0x5ecb [startingBlock] => 0x3e2db4 )

#0 /var/www/html/plugins/ethereum/ethereum-php/src/Ethereum.php(203): Ethereum\Ethereum->createReturnValue(Array, 'EthB', 'eth_syncing')
#1 [internal function]: Ethereum\Ethereum->Ethereum{closure}()
#2 /var/www/html/plugins/ethereum/ethereum-php/src/Ethereum.php(221): call_user_func_array(Object(Closure), Array)
#3 /var/www/html/plugins/ethereum/ethereum-php/src/EthMethods.php(136): Ethereum\Ethereum->__call('eth_syncing', Array)
#4 /var/www/html/plugins/ethereum/ethereum-php/public/client-example.php(62): Ethereum\Ethereum->eth_syncing()
#5 /var/www/html/plugins/ethereum/ethereum-php/public/client-example.php(33): status(Object(Ethereum\Ethereum))
#6 {main}

I want to interact with that node from my browser to create wallet public addresses for each user and do transactions and get wallet balance. Are these functions possible with this plugin.?

Guzzle Issue

graze/guzzle-jsonrpc[3.0.0, ..., 3.2.1] require guzzlehttp/guzzle ^6.0 -> found guzzlehttp/guzzle[6.0.0, ..., 6.5.x-dev] but it conflicts with your root composer.json require (^7.0.1).
- digitaldonkey/ethereum-php dev-master requires graze/guzzle-jsonrpc ~3.0 -> satisfiable by graze/guzzle-jsonrpc[3.0.0, 3.1.0, 3.2.0, 3.2.1].
- Root composer.json requires digitaldonkey/ethereum-php 9999999-dev -> satisfiable by digitaldonkey/ethereum-php[].

Join or collaborate with web3.php

Currently, there two (maybe even more) Ethereum / Web3 libraries for PHP, digitaldonkey/ethereum-php and sc0Vu/web3.php. Both are great and they have some special features.

It will be great if they will be joined or collaborated. They could grew up and maybe someday even became the "official" PHP Ethereum / Web3 library under Ethereum organization on GitHub. It could be hard, but it would be great.

If they joined, I recommend to use name web3.php because other Ethereum / Web3 implementations are using web3.{lang} (web3.js, web3.py) so it would be better to use this standard.

When preloading enabled nested package pear/math_biginteger undefined constant error

PHP 7.4.25 (cli) (built: Nov 13 2021 09:50:49) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.25, Copyright (c), by Zend Technologies
    with Xdebug v2.9.8, Copyright (c) 2002-2020, by Derick Rethans
pear/math_biginteger                    v1.0.3
digitaldonkey/ethereum-php          dev-master 650b470

Error:

php.WARNING: Warning: Use of undefined constant MATH_BIGINTEGER_MODE_GMP - assumed 'MATH_BIGINTEGER_MODE_GMP' (this will throw an Error in a future version of PHP) {"exception":"[object] (ErrorException(code: 0): Warning: Use of undefined constant MATH_BIGINTEGER_MODE_GMP - assumed 'MATH_BIGINTEGER_MODE_GMP' (this will throw an Error in a future version of PHP) at /var/www/vendor/pear/math_biginteger/Math/BigInteger.php:336)

Preloading enabled

opcache.preload => /var/www/config/preload.php => /var/www/config/preload.php
opcache.preload_user => www-data => www-data

Unknown ABI type: tuple[]

Using the pragma abicoder v2 in my solidity smart contract, I have this error when the result of the method called returns an array of struct.

Thx for your work !

EC recover PHP implementation

Ethereum based challenge/response authentication can be implemented using web3.eth.sign and ecrecover.

Current state

The Ethereum specialties like message prefixing are implemented, but we still missing a propper PHP implementation. There is Library contract based recovery, but it seems a very huge overhead and is hard to implement consistently in a Library which is supposed to be working on any network.

Currently I work around that using a ugly bash wrapper and call node based ecrecory.

if (defined('ETHEREUM_ECRECOVER')) {
$call = str_replace(
array('#m#', '#v#', '#r#', '#s#'),
array($message_hash->hexVal(), $sig['v']->hexVal(), $sig['r']->hexVal(), $sig['s']->hexVal()),
ETHEREUM_ECRECOVER
);
$address = new EthD20(self::ensureHexPrefix(substr(shell_exec($call), 0, 42)));
}
else {
// $address = $this->ecrecovery($message_hash, $v, $r, $s);
// $this->contractEcRecover($message, EthD $signature, EthD20 $public_key)
throw new \Exception('EC verifications on contract level is not implemented yet.');
}

What we need

Priority implementing EC verify is portability: It should work on a PHP standard machine depending only on PHP composer libraries in the first place. I consider performance secondary, because we could add a fallback on a PHP-Extension if available.

Currently I would consider a math based approach using the included Math_BigInteger as the best solution without external dependencies.

Alternatively there are multiple ecc libraries (phpecc, ecc_phgp, elliptic-php). My problem using them so far was their dependency on standard key files (PHP-ecc) which I didn't get together with the Ethereum specialty that the address is actually a derivate of the public key. But I didn't try them all yet.

Later performance improvements

There are also PHP-Extension based solutions like secp256k1-php, which might be used to tewak performance later, but I want to try to keep the libraries PHP requirements minimal.

Unable to connect when $eth->eth_protocolVersion

`try {
// Connect to Ganache
$eth = new Ethereum('http://127.0.0.1:8545');
$eth->eth_getBalance()

        $result = $eth->eth_getBalance(["0xc94770007dda54cF92009BFF0dE90c06F603a09f","latest"]);
        var_dump($result);
    }
    catch (\Exception $exception) {
        die ("Unable to connect.");
    }`

return: syntax error, unexpected '$result' (T_VARIABLE)

Compatibility Question

Is this library Drupal only or can I use it to create a generic procedural PHP application?

Unable to use address parameter for ERC20 contracts

Hi,

I'm trying to fetch account balances from ERC20 smart contracts.
To do so, I have the ERC20 standard ABI, so I should just have to call the "balanceOf" function of the contracts.
According to the ABI, the "balanceOf" function has just one input : the account address.

Here is my piece of code with a specific example where $abi_json is a json of the ERC20 ABI:

$contract_address = "0x123ab195dd38b1b40510d467a6a359b201af056f";
$account_address = "0xcc7d71df5e7b6c765448fb7ec79a602d6e3ab4f8";
$abi = new Abi(json_decode($abi_json));
$response=$eth->eth_call(new CallTransaction(new EthD20($contract_address), 
    null, null, null, null, 
    $abi->encodeFunction("balanceOf",[new EthD20($account_address)])), 
    new EthBlockParam());

It turns out that the response value is 0, but it should be positive with this particular provided addresses.

I added logs in the Ethereum::request method and I found out that the "data" field sent is :
0x70a08231cc7d71df5e7b6c765448fb7ec79a602d6e3ab4f8.
The first 8 characters 70a08231 represent the signature of the "BalanceOf" function, and the rest is the address sent as an input, on 40 characters.

But it looks like the Ethereum Node is expecting this address to be padded in a 64 characters string.
I could prove that with the geth js console on my Parity node :

> eth.call({to:"0x123ab195dd38b1b40510d467a6a359b201af056f" , data: "0x70a08231cc7d71df5e7b6c765448fb7ec79a602d6e3ab4f8"});
"0x0000000000000000000000000000000000000000000000000000000000000000"
> eth.call({to:"0x123ab195dd38b1b40510d467a6a359b201af056f" , data: "0x70a08231000000000000000000000000cc7d71df5e7b6c765448fb7ec79a602d6e3ab4f8"});
"0x00000000000000000000000000000000000000000000000000000198a3bd5246"

Am I doing something wrong while preparing the "eth_call" request ? How should I do it so that the address is padded to a 64 characters string in the data field ?

How can I call the contract method 'getAmountsOut' with 'address[]' params?

I wath get the price from pancakeswap router contract: https://bscscan.com/address/0x10ED43C718714eb63d5aA57B78B54704E256024E

abi:

{"internalType":"address[]","name":"path","type":"address[]"}],"name":"getAmountsOut","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"view","type":"function"}

code:

$eth = new Ethereum($url);
$w = new SmartContract($abi, self::PANCAKE_SWAP_ROUTER_CONTRACT_ADDRESS, $eth);

$price = $w->getAmountsOut(
            new EthQ(1, ['abi' => 'uint256'])
            new EthD($path, ['abi' => 'address[]'])
        )->val();

I dont know how to new the address[] ABI type object
then got the err:

substr() expects parameter 1 to be string, array given

How can I fix it?

Unable to send bytes as argument

My contract:

contract MyContract {
    function b1(bytes b) public pure returns (uint) {
        return b.length;
    }
    function b2(bytes32 b) public pure returns (uint) {
        return b.length;
    }
}

I'm able to call b1 from browser console:

myContract.b1('Hello', function (e,v) { console.log(v.toNumber()) }) // 5
myContract.b1(web3.toHex('Hello'), function (e,v) { console.log(v.toNumber()) }) // 5

But I can't get the correct result from ethereum-php:

echo $myContract->b1(new EthS('Hello!!'))->val(); // 0
echo $myContract->b1(new EthD('0x48656c6c6f'))->val(); // 0

Instead, send bytes32 as argument to b2 is fine:

echo $myContract->b2(new EthD32('0x'.md5(1).md5(1)))->val(); // 32

Support for management APIs

Any chance you could expand your library to include support for the management APIs (such as personal, miner, etc.)? I see you support some personal APIs but for example the "personal_newAccount" seem to be missing. Thanks a lot for providing this, it's very useful.

Fix this.

$topic = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
$filter = new \Ethereum\Filter(new Ethereum\EthBlockParam(), new Ethereum\EthBlockParam(), new \Ethereum\EthData($coin->contract_address) , [$topic]);
$filter_id = $ether->eth_newFilter($filter);

No class D in in ethstatic
Problem is in this file, src/Filter.php
line 76
(!is_null($this->topics)) ? $return['topics'] = EthereumStatic::valueArray($this->topics, 'D') : array();

Works after edit

(!is_null($this->topics)) ? $return['topics'] = EthereumStatic::valueArray($this->topics, '\Ethereum\EthD') : array();

Data Field

Can I generate via your tool the data field for transaction made to SmartContract?

curl_setopt_array(): Unable to create temporary file

My computer is Windows10 link can link normally, but call eth_coinbase, curl_setopt_array (): Unable to create temporary file

Call link printing is true
$eth=new Ethereum('http://192.168.1.144:8545');
print_r($eth);
but eth_coinbase return curl_setopt_array(): Unable to create temporary file.
$ret=$eth->eth_coinbase();
print_r($ret);

The same commands are the same

Fatal error: Uncaught Error: Class 'EthereumController' not found

I cloned master branch into public html and installed dependencies through composer. I want to to use this project to interact with my php website and a go-ethereum node running on another server. I can interact with that using geth console and curl function in the terminal. But I want to interact with that node from my browser to create wallet addresses and do transactions and get wallet balance. Are these functions possible with this plugin.?

I created a php file in the 'ethereum-php' folder and included below code
try { $eth = new EthereumController(); echo $eth->client->eth_protocolVersion(); } catch (\Exception $exception) { die ("Unable to connect."); }
But it gives

Fatal error: Uncaught Error: Class 'EthereumController' not found in /var/www/html/plugins/ethereum/digitaldonkey/ethereum-php/stestdd.php:6 Stack trace: #0 {main} thrown in /var/www/html/plugins/ethereum/digitaldonkey/ethereum-php/stestdd.php on line 6

Please help! Thanks in Advance.

Bloom filters

If you application requires you to analyze blocks it would be great to make use of Bloom filters.

Bloom filters enable you to test with little effort, if the Block content might be relevant for your application. They key feature: You might get some false positives (which you would eliminate in a subsequent request on the block data), but you don't require to process the full data of any block, as false negatives are not possible.

http://www.badykov.com/ethereum/2017/10/29/ethereum-bloom-filter/

In order to implement bloom filters you need to have a passion for bytes and math.

Anyone does?

Illegal offset type in isset or empty --- EthDataTypePrimitive.php LINE 75

I tried to execute the function eth_accounts and I got the exception
Illegal offset type in isset or empty in the file EthDataTypePrimitive.php on line 75

$eth = new Ethereum('http://localhost:8545');
echo '<pre>';
print_r($eth->eth_accounts());

The function that is giving the exception is typeMap because is receiving an array instead of a string.

The problem seems to be in the file Ethereum.php on line 152

$is_primitive = (bool) EthDataTypePrimitive::typeMap($return_type);

where $return_type is an array and not a string.

I solved adding the following line of code at the beginning of the function typeMap but I don't think this is the best solution

if (is_array($type) and isset($type[0])) $type = $type[0];

Class 'Ethereum\DataType\Ethereum' not found

Symfony\Component\Debug\Exception\FatalThrowableError : Class 'Ethereum\DataType\Ethereum' not found

at vendor/digitaldonkey/ethereum-php/src/DataType/Filter.php:73
69| $return = [];
70| (!is_null($this->fromBlock)) ? $return['fromBlock'] = $this->fromBlock->hexVal() : NULL;
71| (!is_null($this->toBlock)) ? $return['toBlock'] = $this->toBlock->hexVal() : NULL;
72| (!is_null($this->address)) ? $return['address'] = $this->address->hexVal() : NULL;

73| (!is_null($this->topics)) ? $return['topics'] = Ethereum::valueArray($this->topics, 'EthD') : array();
74| return $return;
75| }
76| }

Fatal error: Call to a member function getType() on string in /var/www/html/harleyq/ether-php/src/Ethereum.php on line 102

@digitaldonkey

ethereumTester.php

Fatal error: Call to a member function getType() on string in /var/www/html/harleyq/ether-php/src/Ethereum.php on line 102

` $args = func_get_args();
if (count($args) && isset($argument_class_names)) {
$this->debug('Arguments', $args);

      // Validate arguments.
      foreach ($args as $i => $arg) {

        if ($argument_class_names[$i] !== $arg->getType()) {
          throw new \InvalidArgumentException("Argument $i is " . $arg->getType() . " but expected $argument_class_names[$i] in $method().");
        }
        else {`

how $arg could be EthS object if it is basic function argument?

NOT IN RANGE exception for smart contract call that returns many values.

I am receiving the following exception
InvalidArgumentException NOT IN RANGE: 100345 ... 082244 > (u)int256
when I am trying to retrieve information from a smart contract that returns several values.

The exception is raised by the line 92 of the file SmarContract.php
$return = $return->convertByAbi($returnTypeAbi);

This is the declaration of the function getProductById on the smart contract:

function getProductById(uint id) public view
returns (
	uint,
	string,
	bytes32,
	uint,
	uint,
	uint[],
	bool
) {
	...
}

I think the issue is caused by:

$returnTypeAbi = $m->outputs[0]->type;
$return = $return->convertByAbi($returnTypeAbi);

where it is trying to convert the response (that is the concatenation of all smartcontract data) into a UINT (that is the first type $m->outputs[0] ).


FYI: the ABI is correctly loaded in fact if I dump the $m->outputs in the line 91 of the file SmartContract.php I can see the value types list declared in the smart contrct function.

extend class EthDataType

@digitaldonkey
Declaration of Ethereum\Transaction::setValue(Ethereum\EthQ $value) should be compatible with Ethereum\EthDataType::setValue($val, array $params = Array)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.