Update ripple-lib samples to 1.10.0

- Removes lodash dependecy for web version
- Uses the new generateFaucetWallet() API method
- Make 'issue a token' code capable of running in-browser or in Node.js
  without modification
This commit is contained in:
mDuo13
2021-08-24 14:38:07 -07:00
parent cff0fcc716
commit d6e06ae140
18 changed files with 52 additions and 89 deletions

View File

@@ -2,6 +2,6 @@
This code demonstrates how to issue a (fungible) token on the XRP Ledger. For a detailed explanation, see <https://xrpl.org/issue-a-fungible-token.html>.
The code is designed to run in-browser by loading `demo.html` and watching the console output. To run it in Node.js, you must uncomment three `require()` lines towards the top of `issue-a-token.js` and use your preferred package manager (such as `yarn` or `npm`) to install the dependencies.
The code is designed to run in-browser by loading `demo.html` and watching the console output or in Node.js. For Node.js, you must first install the dependencies using your preferred package manager (such as `yarn` or `npm`).
In both cases you also need [the `submit-and-verify.js` code from another folder of this repository](../submit-and-verify/). It should already be in the right place if you cloned or download an archive of the repo.

View File

@@ -3,9 +3,8 @@
<head>
<meta charset="utf-8" />
<title>Code Sample - Issue a Token</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js" integrity="sha512-WFN04846sdKMIP5LKNphMaWzU7YpMyCU245etK3g/2ARYbPK9Ub18eG+ljU96qKRCWh+quCY7yefSmlkQw1ANQ==" crossorigin="anonymous"></script>
<script src="https://unpkg.com/ripple-lib@1.9.8/build/ripple-latest-min.js"></script>
<script type="application/javascript" src="../submit-and-verify/submit-and-verify.js"></script>
<script src="https://unpkg.com/ripple-lib@1.10.0/build/ripple-latest-min.js"></script>
<script type="application/javascript" src="../../submit-and-verify/submit-and-verify.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

@@ -1,11 +1,13 @@
// Stand-alone code sample for the "issue a token" tutorial:
// https://xrpl.org/issue-a-fungible-token.html
// Uncomment these dependencies for Node.js. In browsers, use <script> tags as
// in the example demo.html.
// const ripple = require('ripple-lib')
// const fetch = require('node-fetch')
// const submit_and_verify = require('../submit-and-verify/submit-and-verify.js').submit_and_verify
// Dependencies for Node.js.
// In browsers, use <script> tags as in the example demo.html.
if (typeof module !== "undefined") {
// gotta use var here because const/let are block-scoped to the if statement.
var ripple = require('ripple-lib')
var submit_and_verify = require('../../submit-and-verify/submit-and-verify.js').submit_and_verify
}
// Connect ---------------------------------------------------------------------
async function main() {
@@ -14,32 +16,13 @@ async function main() {
await api.connect()
// Get credentials from the Testnet Faucet -----------------------------------
// This doesn't technically need to happen after you call api.connect() but
// it's convenient to do here.
async function get_faucet_address() {
const faucet_url = "https://faucet.altnet.rippletest.net/accounts"
const faucet_options = {
method: 'POST',
headers: {
"Content-Type": "application/json"
},
body: '{}'
}
const response = await fetch(faucet_url, faucet_options)
if (!response.ok) {
throw `Faucet returned an error: ${data.error}`
}
const data = await response.json()
return data
}
console.log("Requesting addresses from the Testnet faucet...")
const hot_data = await get_faucet_address()
const hot_address = hot_data.account.address
const hot_data = await api.generateFaucetWallet()
const hot_address = hot_data.account.classicAddress
const hot_secret = hot_data.account.secret
const cold_data = await get_faucet_address()
const cold_address = cold_data.account.address
const cold_data = await api.generateFaucetWallet()
const cold_address = cold_data.account.classicAddress
const cold_secret = cold_data.account.secret
console.log("Waiting until we have a validated starting sequence number...")

View File

@@ -1,6 +1,5 @@
{
"dependencies": {
"node-fetch": "^2.6.1",
"ripple-lib": "^1.9.8"
"ripple-lib": "^1.10.0"
}
}

View File

@@ -494,10 +494,10 @@ ripple-lib-transactionparser@0.8.2:
bignumber.js "^9.0.0"
lodash "^4.17.15"
ripple-lib@^1.9.8:
version "1.9.8"
resolved "https://registry.yarnpkg.com/ripple-lib/-/ripple-lib-1.9.8.tgz#ff70ec13512531f63f25a560f3683e3a66afc671"
integrity sha512-86wAP4GD6ZVMHIZeqrzn9m8BZSWSpMr06ULaAKNZbN6mxvh7SwcabJjcINRZNpI73Sb3oibWoOsCQ+Vf64WSTA==
ripple-lib@^1.10.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/ripple-lib/-/ripple-lib-1.10.0.tgz#e41aaf17d5c6e6f8bcc8116736ac108ff3d6b810"
integrity sha512-Cg2u73UybfM1PnzcuLt5flvLKZn35ovdIp+1eLrReVB4swuRuUF/SskJG9hf5wMosbvh+E+jZu8A6IbYJoyFIA==
dependencies:
"@types/lodash" "^4.14.136"
"@types/ws" "^7.2.0"