PHP code example of ophelios / php-ethereum-ens

1. Go to this page and download the library: Download ophelios/php-ethereum-ens 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-ens example snippets


use Ens\EnsService;

$rpcUrl = getenv('ENS_PROVIDER_URL') ?: 'https://mainnet.infura.io/v3/<key>';
$ens = new EnsService($rpcUrl);

// Reverse resolve (address -> ENS name)
$name = $ens->resolveEnsName('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'); // vitalik.eth

// Resolve a profile (common records by default)
$profile = $ens->resolveProfile('vitalik.eth');

use Ens\EnsService;

$rpcUrl = getenv('ENS_PROVIDER_URL') ?: 'https://mainnet.infura.io/v3/<key>';
$ens = new EnsService($rpcUrl);

// Resolve single/multiple records (without profile)
$avatar  = $ens->resolveAvatar('vitalik.eth');
$url     = $ens->resolveRecord('vitalik.eth', 'url');
$records = $ens->resolveRecords('vitalik.eth', ['email', 'url']);

use Ens\Web3Client;
use Ens\Configuration;
use Ens\EnsService;

$client = new Web3Client(new Configuration(
    rpcUrl: 'https://mainnet.infura.io/v3/<key>',
    timeoutMs: 10000,
    maxRetries: 3,
));

$ens = new EnsService($client);

composer