PHP code example of php-core / wert-sc-signer

1. Go to this page and download the library: Download php-core/wert-sc-signer 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/ */

    

php-core / wert-sc-signer example snippets


use PHPCore\WertScSigner\WertScSigner;

$signedData = WertScSigner::signSmartContractData($options, $privateKey);

use PHPCore\WertScSigner\Laravel\Facades\WertScSigner;

$dataWithSignature = WertScSigner::signSmartContractData($options);

return [
    'private_key' => env('WERT_PRIVATE_KEY'), // Legacy support

    'credentials' => [
        'default' => env('WERT_PRIVATE_KEY'),
        'production' => env('WERT_PRIVATE_KEY_PRODUCTION'),
        'staging' => env('WERT_PRIVATE_KEY_STAGING'),
        'partner_a' => env('WERT_PRIVATE_KEY_PARTNER_A'),
        'partner_b' => env('WERT_PRIVATE_KEY_PARTNER_B'),
    ],

    'default_credential' => env('WERT_DEFAULT_CREDENTIAL', 'default'),
];

use PHPCore\WertScSigner\Laravel\Facades\WertScSigner;

// Use the default credential (backward compatible)
$dataWithSignature = WertScSigner::signSmartContractData($options);

// Use a specific credential with withCredential()
$dataWithSignature = WertScSigner::withCredential('production')->sign($options);
$dataWithSignature = WertScSigner::withCredential('partner_a')->sign($options);

// Or pass the credential name to the sign() method
$dataWithSignature = WertScSigner::sign($options, 'staging');

// Based on environment
$credential = app()->environment('production') ? 'production' : 'staging';
$dataWithSignature = WertScSigner::withCredential($credential)->sign($options);

// Based on user/tenant
$credential = $user->wert_credential_name ?? 'default';
$dataWithSignature = WertScSigner::withCredential($credential)->sign($options);

// Based on partner
$credential = match($partnerId) {
    'partner-a' => 'partner_a',
    'partner-b' => 'partner_b',
    default => 'default',
};
$dataWithSignature = WertScSigner::withCredential($credential)->sign($options);

$commodity = 'ETH';
$network = 'ethereum';
$options = [
    // address' => '0x742d35Cc6634C0532925a3b844Bc454e4438f44e', // NFT receipient
    'commodity_id' => strtolower($commodity) . '_' . strtolower($network) . '.sc.ethereum',
    'commodity' => $commodity,
    'commodity_amount' => 1.5,
    'network' => $network,
    'sc_address' => '0x...', // smart contract address
    'sc_input_data' => '...', // input data (learn more: https://docs.wert.io/docs/forming-input-data)

    // ...
];

$privateKey = 'your_private_key_here';
$dataWithSignature = WertScSigner::signSmartContractData($options, $privateKey);
bash
php artisan vendor:publish --provider="PHPCore\WertScSigner\Laravel\WertScSignerServiceProvider" --tag="config"