PHP code example of infinitysoftwareltd / walletlibrary

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

    

infinitysoftwareltd / walletlibrary example snippets


Testnet = t
Devnet = x
Mainnet = G

use InfinitySolution\Wallet\Wallet;

use InfinitySolution\Wallet\Network\Infinity\Testnet;

$wallet = (new Wallet(new Testnet))->generateWallet();

use InfinitySolution\Wallet\Network\Infinity\Devnet;

$wallet = (new Wallet(new Devnet))->generateWallet();

use InfinitySolution\Wallet\Network\Infinity\Mainnet;

$wallet = (new Wallet(new Mainnet))->generateWallet();

$data = [
    'fee' => {FEE},
    'amount' => {AMOUNT IN DECIMAL},
    'passphrase' => {SENDER_PASSPHRASE},
    'recipient' => {WALLET_ADDRESS},
    'vendor_field' => {YOUR MESSAGE OR NOTE | THIS IS OPTIONAL}
];

use InfinitySolution\Wallet\Transaction;

$wallet = (new Wallet(new Testnet))->generateWallet();

$data = [
    'amount' => 100000000,
    'passphrase' => $wallet['passphrase'],
    'recipient' => '{RECIPIENT ADDRESS}',
    'vendor_field' => 'Example Message'
];

$sign_transaction = (new Transaction);
$sign_transaction->setTransaction(new \InfinitySolution\Wallet\Transaction\Transfer);
$sign_transaction->data($data);
$sign_transaction->network('Testnet');
$sign_transaction->blockchain('infinity');
$sign_transaction->peer('{IP_PEER}:{PORT}');
return $sign_transaction->build();

$wallet = (new Wallet(new Devnet))->generateWallet();

$data = [
    'amount' => 100000000,
    'passphrase' => $wallet['passphrase'],
    'recipient' => '{RECIPIENT ADDRESS}',
    'vendor_field' => 'Example Message'
];

$sign_transaction = (new Transaction);
$sign_transaction->setTransaction(new \InfinitySolution\Wallet\Transaction\Transfer);
$sign_transaction->data($data);
$sign_transaction->network('Devnet');
$sign_transaction->blockchain('infinity');
$sign_transaction->peer('{IP_PEER}:{PORT}');
return $sign_transaction->build();

$wallet = (new Wallet(new Mainnet))->generateWallet();

$data = [
    'amount' => 100000000,
    'passphrase' => $wallet['passphrase'],
    'recipient' => '{RECIPIENT ADDRESS}',
    'vendor_field' => 'Example Message'
];

$sign_transaction = (new Transaction);
$sign_transaction->setTransaction(new \InfinitySolution\Wallet\Transaction\Transfer);
$sign_transaction->data($data);
$sign_transaction->network('Mainnet');
$sign_transaction->blockchain('infinity');
$sign_transaction->peer('{IP_PEER}:{PORT}');
return $sign_transaction->build();

$data = [
    'fee' => 90,
    'amount' => 100000,
    'passphrase' => '{SENDER_PASSPHRASE}',
    'recipient' => '{RECIPIENT_WALLET_ADDRESS}',
    'vendor_field' => 'TEST MESSAGE'
];

$sign_transaction = (new Transaction);
$sign_transaction->setTransaction(new \InfinitySolution\Wallet\Transaction\Transfer);
$sign_transaction->data($data);
$sign_transaction->network('Mainnet');
$sign_transaction->blockchain('infinity');
$sign_transaction->peer('{IP_PEER}:{PORT}');
$tx = $sign_transaction->build();

$peer = $tx['peer'];

$client = new \GuzzleHttp\Client();
$req = $client->post($peer, ['json'=> $tx['transactions']]);

$data = $req->getBody()->getContents();
if ($data) {
    $data = json_decode($data);
    // This will return an object of ['accept' => ['transaction_id']]
}



$webhook = new Webhook;

$webhook->setProtocol({YOUR PROTOCOL});
$webhook->setIP({YOUR NODE SERVER});
$webhook->setPort({YOUR PORT});

$webhook = new Webhook;

$webhook->setProtocol('http');
$webhook->setIP('63.250.53.87');
$webhook->setPort('4004');

$events = [
    [
        'event' => 'transaction.applied',
        'target' => 'https://{your_endpoint_post}',
        'conditions' => [
            [
                "key" => "recipientId",
                "condition" => "eq",
                "value" => "wallet_address"
            ]
        ]
    ]
];

use InfinitySolution\Wallet\Webhook;

$events = [
        'event' => 'transaction.applied',
        'target' => 'https://{your_endpoint_post}',
        'conditions' => [
            [
                "key" => "recipientId",
                "condition" => "eq",
                "value" => "wallet_address"
            ]
        ]
];

(new Webhook)->create($events);

$events = [
    'event' => 'transaction.applied',
    'target' => 'https://{your_endpoint_post}',
    'conditions' => [
        [
            "key" => "senderPublicKey",
            "condition" => "eq",
            "value" => "{YOUR SENDER PUBLIC KEY}"
        ],
        [
            "key" => "recipientId",
            "condition" => "eq",
            "value" => "{YOUR WALLET ADDRESS}"
        ]
    ]
];

(new Webhook)->create($events);

return (new Webhook)->getAll();

$webhook = new Webhook;
$webhook->setProtocol({YOUR PROTOCOL});
$webhook->setIP({YOUR NODE IP});
$webhook->setPort({YOUR NODE PORT});
return $webhook->getAll();
 

$webhook = new Webhook;
$webhook->setProtocol('http');
$webhook->setIP('63.250.53.87');
$webhook->setPort('4004');
return $webhook->getAll();
 

$webhook = new Webhook;
$webhook->delete({WEBHOOK-ID});

$webhook = new Webhook;
$webhook->delete('bc983be2-1b8a-4415-a9c3-09fda240928d');

$webhook = new Webhook;
$webhook->setProtocol({YOUR PROTOCOL});
$webhook->setIP({YOUR NODE IP});
$webhook->setPort({YOUR NODE PORT});
$webhook->delete({WEBHOOK-ID});

$webhook = new Webhook;
$webhook->setProtocol('http');
$webhook->setIP('63.250.53.87');
$webhook->setPort('4004');
$webhook->delete('bc983be2-1b8a-4415-a9c3-09fda240928d');

use InfinitySolution\Wallet\Fee;

$fees = (new Fee);
$fees->setPeer({URL_PEER});
$fees->setProtocol({PROTOCOL});
$fees->setUrlFee({YOUR_URL_FEE});
return $fees->getFees();

$fees = (new Fee);
$fees->setPeer('api.infinitysolutions.io');
$fees->setProtocol('https');
$fees->setUrlFee('/api/transactions/fees');
return $fees->getFees();

use InfinitySolution\Wallet\Peer;

$peer = (new Peer);
$peer->setIP({YOUR NODE IP});
$peer->setProtocol({YOUR PROTOCOL});
$peer->setUrlParams({YOUR URL PARAMS});
return $peer->getPeers();

$peer = (new Peer);
$peer->setIP('api.infinitysolutions.io');
$peer->setProtocol('https');
$peer->setUrlParams('/api/v2/peers');
return $peer->getPeers();