1. Go to this page and download the library: Download lineage/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/ */
lineage / php example snippets
use Lineage\Client;
$client = new Client(
mempoolHost: 'https://mempool.lineage.to',
storageHost: 'https://storage.lineage.to',
apiKey: 'your-api-key', // optional
valenceHost: 'https://valence.lineage.to', // optional,
use Lineage\Client;
$client = new Client('https://mempool.lineage.to', 'https://storage.lineage.to');
// A pass phrase encrypts/decrypts the wallet and every keypair derived from it.
// Set it before creating or opening a wallet.
$client->setPassPhrase('my very intricate passphrase');
// Create a new wallet. The returned DTO carries the 12-word BIP39 seed phrase –
// store it (and the encrypted wallet) securely; it's the only way to recover funds.
$wallet = $client->createWallet();
echo $wallet->getSeedPhrase();
// Open the wallet (decrypts it in memory) before deriving keypairs.
$client->openWallet($wallet);
// Derive a new address/keypair from the open wallet.
$keypair = $client->createKeypair();
echo $keypair->getAddress();
// Check its balance (new/transferred assets appear here only once the mempool confirms them).
$balance = $client->fetchBalance([$keypair->getAddress()]);
// Create 10 item assets ("Items", the Lineage equivalent of NFTs) at $keypair's
// address, using the well-known default genesis hash.
$itemResult = $client->createItems($keypair, defaultGenesisHash: true, amount: 10);
// Send 1000 Token assets from $keypair to another address, with change (excess)
// returned to $keypair itself.
$client->makeTokenPayment(
paymentAddress: $recipientAddress,
amount: 1000,
allKeypairs: [$keypair],
excessKeypair: $keypair,
);
$balance = $client->fetchBalance([$keypair->getAddress()]);
// $balance['address_list'][$addr][0]['value']['Item']['metadata'] is populated.
// Skip enrichment (issues no resolver calls):
$balance = $client->fetchBalance([$keypair->getAddress()], enrich: false);
// Resolve one item's full genesis facts (metadata, total supply, creator, created block/tx):
$info = $client->getItemInfo($genesisHash);
// Party A offers to pay $sendingAsset to $paymentAddress in exchange for
// $receivingAsset delivered to $receiveKeypair's address. Persist the
// returned pending half until fetchPending2WayPayment reports it settled.
$pendingHalf = $client->make2WayPayment($paymentAddress, $sendingAsset, $receivingAsset, $allKeypairs, $receiveKeypair);
// Both parties poll their own mailboxes: incoming offers are surfaced as
// 'pending'; offers this wallet made that the counterparty has accepted are
// submitted and reported as 'settled'.
['pending' => $pending, 'settled' => $settled] = $client->fetchPending2WayPayment($storedPendingHalves, $allKeypairs);
// Party B accepts (submits its half and notifies valence) or rejects
// (notifies valence only) an offer found in $pending.
$client->accept2WayPayment($details, $allKeypairs);
$client->reject2WayPayment($details, $allKeypairs);
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.