PHP code example of yukazakiri / lepton-agent

1. Go to this page and download the library: Download yukazakiri/lepton-agent 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/ */

    

yukazakiri / lepton-agent example snippets


use Yukazakiri\Lepton\Contracts\AuthGateway;

$auth = app(AuthGateway::class);

$status = $auth->authStatus();
$status['testnet']['authenticated'];  // bool
$status['mainnet']['expires_in'];     // "26d 6h 52m"

// Guard an operation that needs a session.
if (! $auth->isAuthenticatedFor('ARC-TESTNET')) {
    throw new RuntimeException('Log in before transferring on testnet.');
}

// Drive the flow programmatically. The OTP still comes from a human inbox.
$requestId = $auth->beginLogin('[email protected]');
// ... later, after the code arrives ...
$auth->completeLogin($requestId, 'B1X-123456');

$address = config('lepton.arc.treasury');

use Yukazakiri\Lepton\Contracts\WalletGateway;
use Yukazakiri\Lepton\Support\Amounts;

$result = app(WalletGateway::class)->transfer(
    from: '0xTreasury',
    to: '0xRecipient',
    amountBaseUnits: Amounts::fromDecimalString('450.00'), // 450_000000
    options: ['chain' => 'ARC-TESTNET'],
);

$result->txHash;       // 0x…
$result->explorerUrl;  // https://testnet.arcscan.app/tx/0x…
$result->isFake;       // false under the circle driver

use Yukazakiri\Lepton\Facades\Lepton;

Lepton::transferDecimal('0xTreasury', '0xRecipient', '450.00');

// Estimate the fee without moving money.
$result = $wallets->transfer($from, $to, $units, ['estimate' => true]);

// Or set LEPTON_DRY_RUN=true globally.

$onChain = app(ArcNetworkGateway::class)->rpc('eth_getTransactionByHash', [$result->txHash]);
$settled = is_array($onChain) && $onChain !== [];

$balance = $wallets->balance('0xTreasury');
$balance->amountBaseUnits;  // 19_970_000 == 19.97 USDC

use Yukazakiri\Lepton\Contracts\ArcNetworkGateway;

$arc = app(ArcNetworkGateway::class);

$arc->chainCode();      // "ARC-TESTNET"
$arc->chainId();        // 5042002
$arc->blockNumber();    // "0x3d667a7"
$arc->rpcUrl();         // authenticated RPC URL
$arc->explorerUrl($hash);
$arc->addressExplorerUrl($address);

// Native Arc USDC balance, 18 decimals.
$wei = $arc->rpc('eth_getBalance', [$address, 'latest']);
$usdc = Amounts::fromHexQuantity($wei, 18);  // "5.01"

$wallets->limits('0xAgentWallet');  // defaults to mainnet

use Yukazakiri\Lepton\Contracts\X402Gateway;

$services = app(X402Gateway::class);

$services->searchServices('exchange rate');
$services->inspectService('https://api.example.com/rates');

$response = $services->payService('https://api.example.com/rates', '0xPayer', [
    'maxAmount' => '0.01',  // hard ceiling; refuses to overpay
]);

$services->gatewayBalance('0xPayer');

config(['lepton.default' => 'fake']);

// Move money with no chain access.
$wallets = app(WalletGateway::class);
$wallets->seedBalance('0xTreasury', 1_000_000_00);

// Simulate a settled transfer.
$result = $wallets->transfer('0xTreasury', '0xRecipient', 450_00);
$result->isFake;  // true

// Exercise authenticated paths.
app(FakeLeptonGateway::class)->fakeAuthenticated();

$ok = is_array($arc->rpc('eth_getTransactionByHash', [$hash])) && $arc->rpc('eth_getTransactionByHash', [$hash]) !== [];
bash
php artisan vendor:publish --tag=lepton-config
bash
php artisan lepton:login --status
bash
php artisan lepton:login --status                          # session state per network
php artisan lepton:login [email protected]                    # send OTP, get request ID
php artisan lepton:login --request=<id> --otp=B1X-123456    # complete login

php artisan lepton:status --address=0xTreasury             # chain, block, balance, limits
php artisan lepton:transfer 0xRecipient --amount=1.00 --from=0xTreasury
php artisan lepton:transfer 0xRecipient --amount=1.00 --from=0xTreasury --estimate