diff --git a/content/_code-samples/issue-a-token/java/IssueToken.java b/content/_code-samples/issue-a-token/java/IssueToken.java index f12464548d..58431e8bdf 100644 --- a/content/_code-samples/issue-a-token/java/IssueToken.java +++ b/content/_code-samples/issue-a-token/java/IssueToken.java @@ -39,23 +39,20 @@ public class IssueToken { public static void main(String[] args) throws InterruptedException, JsonRpcClientErrorException, JsonProcessingException { - // ----------------------------------------------------------- - // Construct a network client - // ----------------------------------------------------------- + // Construct a network client ---------------------------------------------- HttpUrl rippledUrl = HttpUrl .get("https://s.altnet.rippletest.net:51234/"); XrplClient xrplClient = new XrplClient(rippledUrl); + // Get the current network fee + FeeResult feeResult = xrplClient.fee(); - // ----------------------------------------------------------- - // Create a cold and hot Wallet using a WalletFactory - // ----------------------------------------------------------- + + // Create cold and hot Wallets using a WalletFactory ----------------------- WalletFactory walletFactory = DefaultWalletFactory.getInstance(); Wallet coldWallet = walletFactory.randomWallet(true).wallet(); Wallet hotWallet = walletFactory.randomWallet(true).wallet(); - // ----------------------------------------------------------- - // Fund the account using the testnet Faucet - // ----------------------------------------------------------- + // Fund the account using the testnet Faucet ------------------------------- FaucetClient faucetClient = FaucetClient .construct(HttpUrl.get("https://faucet.altnet.rippletest.net")); faucetClient.fundAccount(FundAccountRequest.of(coldWallet.classicAddress())); @@ -91,14 +88,7 @@ public class IssueToken { } } - // ----------------------------------------------------------- - // Get the current network fee - // ----------------------------------------------------------- - FeeResult feeResult = xrplClient.fee(); - - // ----------------------------------------------------------- - // Configure cold wallet settings - // ----------------------------------------------------------- + // Configure issuer settings ----------------------------------------------- UnsignedInteger coldWalletSequence = xrplClient.accountInfo( AccountInfoRequestParams.builder() .ledgerIndex(LedgerIndex.CURRENT) @@ -127,9 +117,7 @@ public class IssueToken { submitAndWaitForValidation(signedSetDefaultRipple, xrplClient); - // ----------------------------------------------------------- - // Configure hot wallet settings - // ----------------------------------------------------------- + // Configure hot address settings ------------------------------------------ UnsignedInteger hotWalletSequence = xrplClient.accountInfo( AccountInfoRequestParams.builder() .ledgerIndex(LedgerIndex.CURRENT) @@ -158,9 +146,7 @@ public class IssueToken { submitAndWaitForValidation(signedSetRequireAuth, xrplClient); - // ----------------------------------------------------------- - // Create TrustLine - // ----------------------------------------------------------- + // Create trust line ------------------------------------------------------- String currencyCode = "FOO"; ImmutableTrustSet trustSet = TrustSet.builder() .account(hotWallet.classicAddress()) @@ -181,9 +167,7 @@ public class IssueToken { submitAndWaitForValidation(signedTrustSet, xrplClient); - // ----------------------------------------------------------- - // Send token - // ----------------------------------------------------------- + // Send token -------------------------------------------------------------- Payment payment = Payment.builder() .account(coldWallet.classicAddress()) .fee(feeResult.drops().openLedgerFee()) @@ -204,9 +188,7 @@ public class IssueToken { submitAndWaitForValidation(signedPayment, xrplClient); - // ----------------------------------------------------------- - // Check balances - // ----------------------------------------------------------- + // Check balances ---------------------------------------------------------- List lines = xrplClient.accountLines( AccountLinesRequestParams.builder() .account(hotWallet.classicAddress()) @@ -216,6 +198,7 @@ public class IssueToken { System.out.println("Hot wallet TrustLines: " + lines); } + // Helper methods ------------------------------------------------------------ private static UnsignedInteger computeLastLedgerSequence(XrplClient xrplClient) throws JsonRpcClientErrorException { // Get the latest validated ledger index diff --git a/content/_code-samples/issue-a-token/java/README.md b/content/_code-samples/issue-a-token/java/README.md new file mode 100644 index 0000000000..7952454315 --- /dev/null +++ b/content/_code-samples/issue-a-token/java/README.md @@ -0,0 +1,5 @@ +# Issue a Token (Java sample code) + +This code demonstrates how to issue a (fungible) token on the XRP Ledger. For a detailed explanation, see . + +The easiest way to run this code is from an IDE such as IntelliJ. For an example `pom.xml` file, see [Get Started Using Java](https://xrpl.org/get-started-using-java.html). diff --git a/content/_code-samples/issue-a-token/js/README.md b/content/_code-samples/issue-a-token/js/README.md index 8c151a9bc1..fdaa7979f4 100644 --- a/content/_code-samples/issue-a-token/js/README.md +++ b/content/_code-samples/issue-a-token/js/README.md @@ -1,4 +1,4 @@ -# Issue a Token Sample Code +# Issue a Token Sample Code (JavaScript) This code demonstrates how to issue a (fungible) token on the XRP Ledger. For a detailed explanation, see . diff --git a/content/tutorials/use-tokens/issue-a-fungible-token.md b/content/tutorials/use-tokens/issue-a-fungible-token.md index a96656e034..d08d420251 100644 --- a/content/tutorials/use-tokens/issue-a-fungible-token.md +++ b/content/tutorials/use-tokens/issue-a-fungible-token.md @@ -18,12 +18,20 @@ Anyone can issue various types of tokens in the XRP Ledger, ranging from informa - You need two funded XRP Ledger accounts, each with an address, secret key, and some XRP. For this tutorial, you can generate new test credentials as needed. - Each address needs enough XRP to satisfy the [reserve requirement](reserves.html) including the additional reserve for a trust line. - You need a connection to the XRP Ledger network. As shown in this tutorial, you can use public servers for testing. - -This page provides examples that use [ripple-lib for JavaScript](get-started-with-rippleapi-for-javascript.html) or [xrpl-py for Python](get-started-using-python.html). You can also read along and use the interactive steps in your browser without any setup. +- You should be familiar with the Getting Started instructions for your preferred client library. This page provides examples for the following: + - ripple-lib for JavaScript [(Node.js)](get-started-with-rippleapi-for-javascript.html) or [in-browser](get-started.html) + - [xrpl-py for Python](get-started-using-python.html) + - [xrpl4j for Java](get-started-using-java.html). + - You can also read along and use the interactive steps in your browser without any setup. +## Example Code + +Complete sample code for all of the steps of these tutorials is available under the [MIT license](https://github.com/XRPLF/xrpl-dev-portal/blob/master/LICENSE). + +- See [Code Samples: Issue a Fungible Token](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/issue-a-token/) in the source repository for this website. ## Steps {% set n = cycler(* range(1,99)) %} @@ -84,10 +92,14 @@ _Python_ {{ include_code("_code-samples/issue-a-token/py/issue-a-token.py", start_with="# Connect", end_before="# Get credentials", language="py") }} +_Java_ + +{{ include_code("_code-samples/issue-a-token/java/IssueToken.java", start_with="// Construct a network client", end_before="// Create cold", language="java") }} + -**Note:** The code samples in this tutorial use JavaScript's [`async`/`await` pattern](https://javascript.info/async-await). Since `await` needs to be used from within an `async` function, the remaining code samples are written to continue inside the `main()` function started here. You can also use Promise methods `.then()` and `.catch()` instead of `async`/`await` if you prefer. +**Note:** The JavaScript code samples in this tutorial use the [`async`/`await` pattern](https://javascript.info/async-await). Since `await` needs to be used from within an `async` function, the remaining code samples are written to continue inside the `main()` function started here. You can also use Promise methods `.then()` and `.catch()` instead of `async`/`await` if you prefer. For this tutorial, you can connect directly from your browser by pressing the following button: @@ -120,6 +132,8 @@ Other settings you may want to, optionally, configure for your cold address (iss [Tick Size]: ticksize.html [Domain]: accountset.html#domain +You can change these settings later as well. + **Note:** Many issuing settings apply equally to all tokens issued by an address, regardless of the currency code. If you want to issue multiple types of tokens in the XRP Ledger with different settings, you should use a different address to issue each different token. The following code sample shows how to send an [AccountSet transaction][] to enable the recommended cold address settings: @@ -135,6 +149,10 @@ _Python_ {{ include_code("_code-samples/issue-a-token/py/issue-a-token.py", start_with="# Configure issuer", end_before="# Configure hot", language="py") }} +_Java_ + +{{ include_code("_code-samples/issue-a-token/java/IssueToken.java", start_with="// Configure issuer", end_before="// Configure hot", language="java") }} + {{ start_step("Configure Issuer") }} @@ -197,6 +215,12 @@ _Python_ 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. You should wait for your earlier transactions to be fully validated before proceeding to the later steps, to avoid unexpected failures from things executing out of order. For more information, see [Reliable Transaction Submission](reliable-transaction-submission.html). +The code samples in this tutorial use helper functions to wait for validation when submitting a transaction: + +- **JavaScript:** The `submit_and_verify()` function, as defined in the [submit-and-verify code sample](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/submit-and-verify). +- **Python:** The `send_reliable_submission()` [method of the xrpl-py library](https://xrpl-py.readthedocs.io/en/stable/source/xrpl.transaction.html#xrpl.transaction.send_reliable_submission). +- **Java:** The `submitAndWaitForValidation()` method in the [sample Java class](https://github.com/XRPLF/xrpl-dev-portal/blob/master/content/_code-samples/issue-a-token/java/IssueToken.java). + **Tip:** Technically, you can configure the hot address in parallel with configuring the issuer address. For simplicity, this tutorial waits for each transaction one at a time. {{ start_step("Wait (Issuer Setup)") }} @@ -228,6 +252,10 @@ _Python_ {{ include_code("_code-samples/issue-a-token/py/issue-a-token.py", start_with="# Configure hot address", end_before="# Create trust line", language="py") }} +_Java_ + +{{ include_code("_code-samples/issue-a-token/java/IssueToken.java", start_with="// Configure hot address", end_before="// Create trust line", language="java") }} + {{ start_step("Configure Hot Address") }} @@ -306,11 +334,15 @@ _Python_ {{ include_code("_code-samples/issue-a-token/py/issue-a-token.py", start_with="# Create trust line", end_before="# Send token", language="py") }} +_Java_ + +{{ include_code("_code-samples/issue-a-token/java/IssueToken.java", start_with="// Create trust line", end_before="// Send token", language="java") }} + {{ start_step("Make Trust Line") }}
-

Currency code:

+

Currency code:

@@ -322,7 +354,7 @@ _Python_
-
+
@@ -332,10 +364,7 @@ _Python_
-
-
-
 
-
+
@@ -389,6 +418,10 @@ _Python_ {{ include_code("_code-samples/issue-a-token/py/issue-a-token.py", start_with="# Send token", end_before="# Check balances", language="py") }} +_Java_ + +{{ include_code("_code-samples/issue-a-token/java/IssueToken.java", start_with="// Send token", end_before="// Check balances", language="java") }} + {{ start_step("Send Token") }} @@ -451,6 +484,10 @@ _Python_ {{ include_code("_code-samples/issue-a-token/py/issue-a-token.py", start_with="# Check balances", language="py") }} +_Java_ + +{{ include_code("_code-samples/issue-a-token/java/IssueToken.java", start_with="// Check balances", end_before="// Helper", language="java") }} + {{ start_step("Confirm Balances") }}