From 06b79a1b4d57f206eb033737b3fc24cdb57ce388 Mon Sep 17 00:00:00 2001 From: AlexanderBuzz <102560752+AlexanderBuzz@users.noreply.github.com> Date: Mon, 20 Nov 2023 14:11:48 +0100 Subject: [PATCH] Improved samples and documentation --- assets/img/logos/php.svg | 96 +++++++++++++++++++ .../_code-samples/get-started/php/base.php | 8 ++ ...get-acct-info.php => get-account-info.php} | 5 +- .../get-started/get-started-using-php.md | 55 +---------- content/tutorials/get-started/send-xrp.md | 11 ++- template/page-tutorials.html.jinja | 8 +- 6 files changed, 124 insertions(+), 59 deletions(-) create mode 100644 assets/img/logos/php.svg rename content/_code-samples/get-started/php/{get-acct-info.php => get-account-info.php} (78%) diff --git a/assets/img/logos/php.svg b/assets/img/logos/php.svg new file mode 100644 index 0000000000..37a5e6fe7e --- /dev/null +++ b/assets/img/logos/php.svg @@ -0,0 +1,96 @@ + + \ No newline at end of file diff --git a/content/_code-samples/get-started/php/base.php b/content/_code-samples/get-started/php/base.php index 1a49a4f668..8efa45a794 100644 --- a/content/_code-samples/get-started/php/base.php +++ b/content/_code-samples/get-started/php/base.php @@ -16,3 +16,11 @@ $wallet = Wallet::generate(); // Fund (and activate) the wallet fundWallet($client, $wallet); + +// print wallet properties +print_r([ + 'publicKey' => $wallet->getPublicKey(), + 'privateKey' => $wallet->getPrivateKey(), + 'classicAddress' => $wallet->getAddress(), + 'seed' => $wallet->getSeed() +]); diff --git a/content/_code-samples/get-started/php/get-acct-info.php b/content/_code-samples/get-started/php/get-account-info.php similarity index 78% rename from content/_code-samples/get-started/php/get-acct-info.php rename to content/_code-samples/get-started/php/get-account-info.php index 7788a01d5b..fc38176211 100644 --- a/content/_code-samples/get-started/php/get-acct-info.php +++ b/content/_code-samples/get-started/php/get-account-info.php @@ -18,11 +18,14 @@ $wallet = Wallet::generate(); // Fund (and activate) the wallet fundWallet($client, $wallet); +// Create an AccountInfoRequest method $accountInfoRequest = new AccountInfoRequest( account: $wallet->getAddress(), ledgerIndex: 'validated' ); -$accountInfoResponse = $client->syncRequest(($accountInfoRequest)); +// Send the request to the XRPL +$accountInfoResponse = $client->syncRequest($accountInfoRequest); +// Print formatted response print_r($accountInfoResponse); diff --git a/content/tutorials/get-started/get-started-using-php.md b/content/tutorials/get-started/get-started-using-php.md index 6ae4fd6f83..843bde3ee5 100644 --- a/content/tutorials/get-started/get-started-using-php.md +++ b/content/tutorials/get-started/get-started-using-php.md @@ -136,26 +136,7 @@ print_r([ For testing and development purposes, you can use the `fundWallet()` helper function on the XRP Ledger [Testnet](parallel-networks.html): -```php -getAddress(), - ledgerIndex: 'validated' - ); - -// Send AccountInfo request -$accountInfoResponse = $client->syncRequest(($accountInfoRequest)); - -print_r($accountInfoResponse); -``` +{{ include_code("_code-samples/get-started/php/get-account-info.php", language="php", start_with="// Create an AccountInfoRequest") }} ### 4. Starting the script @@ -207,7 +158,7 @@ To run the app, you can copy the code from [this website's GitHub Repository]({{ ```console composer require hardcastle/xrpl_php -php get-acct-info.php +php get-account-info.php ``` You should see output similar to this example: diff --git a/content/tutorials/get-started/send-xrp.md b/content/tutorials/get-started/send-xrp.md index 77c8adb194..f1d7ddd451 100644 --- a/content/tutorials/get-started/send-xrp.md +++ b/content/tutorials/get-started/send-xrp.md @@ -139,10 +139,11 @@ _Java_ {{ include_code("_code-samples/send-xrp/java/SendXrp.java", start_with="// Prepare", end_before="// Sign", language="java") }} -_Java_ +_PHP_ {{ include_code("_code-samples/send-xrp/php/send-xrp.php", start_with="// Transaction definition", end_before="// Sign", language="php") }} + {{ start_step("Prepare") }} @@ -190,7 +191,7 @@ _Java_ start_with="// Sign", end_before="// Submit", language="java" ) }} -_Java_ +_PHP_ {{ include_code("_code-samples/send-xrp/php/send-xrp.php", start_with="// Sign", end_before="// Submit", language="php" ) }} @@ -211,7 +212,7 @@ The result of the signing operation is a transaction object containing a signatu {{ end_step() }} -### {{n.next()}}. Submit the Signed Blob +### 5. Submit the Signed Blob Now that you have a signed transaction, you can submit it to an XRP Ledger server, which relays it through the network. It's also a good idea to take note of the latest validated ledger index before you submit. The earliest ledger version that your transaction could get into as a result of this submission is one higher than the latest validated ledger when you submit it. Of course, if the same transaction was previously submitted, it could already be in a previous ledger. (It can't succeed a second time, but you may not realize it succeeded if you aren't looking in the right ledger versions.) @@ -257,7 +258,7 @@ example transaction {{ end_step() }} -### 5. Wait for Validation +### 6. Wait for Validation Most transactions are accepted into the next ledger version after they're submitted, which means it may take 4-7 seconds for a transaction's outcome to be final. If the XRP Ledger is busy or poor network connectivity delays a transaction from being relayed throughout the network, a transaction may take longer to be confirmed. (For more information on expiration of unconfirmed transactions, see [Reliable Transaction Submission](reliable-transaction-submission.html).) @@ -294,7 +295,7 @@ _PHP_ {{ end_step() }} -### 6. Check Transaction Status +### 7. Check Transaction Status To know for sure what a transaction did, you must look up the outcome of the transaction when it appears in a validated ledger version. diff --git a/template/page-tutorials.html.jinja b/template/page-tutorials.html.jinja index f432a2bdc5..cb4ab2d0e0 100644 --- a/template/page-tutorials.html.jinja +++ b/template/page-tutorials.html.jinja @@ -26,6 +26,12 @@ "href": "javascript.html", "img": "./assets/img/logos/javascript.svg", }, + { + "title": "PHP", + "description": "Using the XRPL_PHP client library.", + "href": "php.html", + "img": "./assets/img/logos/php.svg", + }, { "title": "HTTP & Websocket APIs", "description": "Access the XRP Ledger directly through the APIs of its core server.", @@ -158,7 +164,7 @@ {% else %}
{{description}}