PHP code example of mitoop / crypto-php

1. Go to this page and download the library: Download mitoop/crypto-php 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/ */

    

mitoop / crypto-php example snippets


use Mitoop\Crypto\Factory;

// 获取原生币实例
$coin = Factory::createCoin([
   'chain' => 'eth', // 链类型:eth / bsc / polygon / tron
   'chain_id' => 11155111, // 链ID(Tron 设置为0)
   'rpc_url' => 'https://sepolia.infura.io/v3/your_api_key',
   'rpc_api_key' => '', // 如无可留空
   'explorer_url' => 'https://sepolia.etherscan.io'
]);

$coin->generateWallet();
$coin->getBalance();
// ...

// 获取代币实例
$token = Factory::createToken([
   'chain' => 'eth',
   'chain_id' => 11155111,
   'contract_address' => '0x779877A7B0D9E8603169DdbD7836e478b4624789',
   'decimals' => 18,
   'rpc_url' => 'https://sepolia.infura.io/v3/your_api_key',
   'rpc_api_key' => '',
   'explorer_url' => 'https://sepolia.etherscan.io'
]);

$token->generateWallet();
$token->getBalance();
// ...

// 通过代币实例获取原生币实例
$nativeCoin = $token->getNativeCoin();
$nativeCoin->getBalance();
// ...
bash
composer