xrpl.js 2.0 release edits

- Final CDN URLs; remove TODOs
- Update sample code in Use Tickets tutorial
This commit is contained in:
mDuo13
2021-10-20 11:27:17 -07:00
parent bea3f71601
commit 92a8faecac
17 changed files with 161 additions and 139 deletions

View File

@@ -3,9 +3,7 @@
<head>
<meta charset="utf-8" />
<title>Code Sample - Issue a Token</title>
<!-- TODO: re-add CDN version instead of local version
<script src="https://unpkg.com/ripple-lib@1.10.0/build/ripple-latest-min.js"></script> -->
<script type="application/javascript" src="../../../assets/js/xrpl-2.0.0preview.min.js"></script>
<script src="https://unpkg.com/xrpl@2.0.0/build/xrpl-latest-min.js"></script>
<script type="application/javascript" src="issue-a-token.js"></script>
</head>
<body>Open your browser's console (F12) to see the logs.</body>

View File

@@ -2,9 +2,7 @@
<html>
<head>
<meta charset="utf-8" />
<!-- TODO: re-add CDN version instead of local version
<script src="https://unpkg.com/ripple-lib@1.10.0/build/ripple-latest-min.js"></script> -->
<script type="application/javascript" src="../../../assets/js/xrpl-2.0.0preview.min.js"></script>
<script src="https://unpkg.com/xrpl@2.0.0/build/xrpl-latest-min.js"></script>
<script type="application/javascript" src="require-destination-tags.js"></script>
</head>
<body>Open your browser's console (F12) to see the logs.</body>

View File

@@ -3,9 +3,7 @@
<head>
<meta charset="utf-8" />
<title>Code Sample - Send XRP</title>
<!-- TODO: re-add CDN version instead of local version
<script src="https://unpkg.com/ripple-lib@1.10.0/build/ripple-latest-min.js"></script> -->
<script type="application/javascript" src="../../../assets/js/xrpl-2.0.0preview.min.js"></script>
<script src="https://unpkg.com/xrpl@2.0.0/build/xrpl-latest-min.js"></script>
<script type="application/javascript" src="send-xrp.js"></script>
</head>
<body>Open your browser's console (F12) to see the logs.</body>

View File

@@ -37,7 +37,6 @@ async function main() {
// Submit signed blob --------------------------------------------------------
const tx = await client.submitAndWait(signed.tx_blob)
// This raises an exception if the transaction isn't confirmed.
// Wait for validation -------------------------------------------------------
// submitAndWait() handles this automatically, but it can take 4-7s.

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Code Sample - Use Tickets</title>
<script src="https://unpkg.com/xrpl@2.0.0/build/xrpl-latest-min.js"></script>
<script type="application/javascript" src="use-tickets.js"></script>
</head>
<body>Open your browser's console (F12) to see the logs.</body>
</html>

View File

@@ -0,0 +1,5 @@
{
"dependencies": {
"xrpl": "^2.0.0"
}
}

View File

@@ -0,0 +1,76 @@
// Dependencies for Node.js.
// In browsers, use a <script> tag instead.
if (typeof module !== "undefined") {
// gotta use var here because const/let are block-scoped to the if statement.
var xrpl = require('xrpl')
}
// Example credentials
const wallet = xrpl.Wallet.fromSeed("sn3nxiW7v8KXzPzAqzyHXbSSKNuN9")
// Connect to Devnet (since that's where tickets are available)
async function main() {
const client = new xrpl.Client("wss://s.devnet.rippletest.net:51233")
await client.connect()
// Get credentials from the Testnet Faucet -----------------------------------
console.log("Getting a wallet from the faucet...")
const {wallet, balance} = await client.fundWallet()
// Check Sequence Number -----------------------------------------------------
const account_info = await client.request({
"command": "account_info",
"account": wallet.address
})
let current_sequence = account_info.result.account_data.Sequence
// Prepare and Sign TicketCreate ---------------------------------------------
const prepared = await client.autofill({
"TransactionType": "TicketCreate",
"Account": wallet.address,
"TicketCount": 10,
"Sequence": current_sequence
})
const signed = wallet.sign(prepared)
console.log(`Prepared TicketCreate transaction ${signed.hash}`)
// Submit TicketCreate -------------------------------------------------------
const tx = await client.submitAndWait(signed.tx_blob)
console.log(tx)
// Wait for Validation -------------------------------------------------------
// submitAndWait() handles this automatically, but it can take 4-7s.
// Check Available Tickets ---------------------------------------------------
let response = await client.request({
"command": "account_objects",
"account": wallet.address,
"type": "ticket"
})
console.log("Available Tickets:", response.result.account_objects)
// Choose an arbitrary Ticket to use
use_ticket = response.result.account_objects[0].TicketSequence
// Prepare and Sign Ticketed Transaction -------------------------------------
const prepared_t = await client.autofill({
"TransactionType": "AccountSet",
"Account": wallet.address,
"TicketSequence": use_ticket,
"LastLedgerSequence": null, // Never expire this transaction.
"Sequence": 0
})
const signed_t = wallet.sign(prepared_t)
console.log(`Prepared ticketed transaction ${signed_t.hash}`)
// Submit Ticketed Transaction -----------------------------------------------
const tx_t = await client.submitAndWait(signed_t.tx_blob)
console.log(tx_t)
// Wait for Validation (again) -----------------------------------------------
// Disconnect when done (If you omit this, Node.js won't end the process)
client.disconnect()
}
main()