PHP code example of ophelios / php-ethereum-moralis
1. Go to this page and download the library: Download ophelios/php-ethereum-moralis library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ophelios / php-ethereum-moralis example snippets
use Moralis\MoralisService;
$apiKey = getenv('MORALIS_API_KEY');
$service = new MoralisService($apiKey);
// Fetch an ERC‑20 price (defaults to chain "eth")
$token = $service->fetchToken('0x289ff00235d2b98b0145ff5d4435d3e92f9540a6');
echo $token->tokenName . " (" . $token->tokenSymbol . ") => $" . $token->usdPrice . "\n";
use Moralis\MoralisService;
use Ophelios\Cache\ApcuCache; // from ophelios/php-apcu-cache
$service = new MoralisService(getenv('MORALIS_API_KEY'));
$service->setCache(new ApcuCache());
$token = $service->fetchToken('0x289ff00235d2b98b0145ff5d4435d3e92f9540a6');
use Moralis\Configuration;
use Moralis\MoralisClient;
use Moralis\MoralisService;
$cfg = new Configuration(
apiKey: getenv('MORALIS_API_KEY'),
baseUrl: 'https://deep-index.moralis.io/api/v2.2/',
timeout: 10,
);
$client = new MoralisClient($cfg);
$service = new MoralisService($client);
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.