mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-19 11:15:49 +00:00
Issue a token: start code sample
This commit is contained in:
75
content/_code-samples/issue-a-token/issue-a-token.js
Normal file
75
content/_code-samples/issue-a-token/issue-a-token.js
Normal file
@@ -0,0 +1,75 @@
|
||||
// Example credentials
|
||||
let hot_address = "rMCcNuTcajgw7YTgBy1sys3b89QqjUrMpH"
|
||||
let hot_secret = "sn3nxiW7v8KXzPzAqzyHXbSSKNuN9"
|
||||
let cold_address = ""
|
||||
let cold_secret = ""
|
||||
|
||||
// Connect ---------------------------------------------------------------------
|
||||
// ripple = require('ripple-lib') // For Node.js. In browsers, use <script>.
|
||||
api = new ripple.RippleAPI({server: 'wss://s.altnet.rippletest.net:51233'})
|
||||
api.connect()
|
||||
api.on('connected', async () => {
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
const hot_data = await get_faucet_address()
|
||||
hot_address = hot_data.account.address
|
||||
hot_secret = hot_data.account.secret
|
||||
|
||||
const cold_data = await get_faucet_address()
|
||||
cold_address = cold_data.account.address
|
||||
cold_secret = cold_data.account.secret
|
||||
|
||||
console.log("Waiting until we have a validated starting sequence number...")
|
||||
// If you go too soon, the funding transaction might slip back a ledger and
|
||||
// then your starting Sequence number will be off. This is mostly relevant
|
||||
// when you want to use a Testnet account right after getting a reply from
|
||||
// the faucet.
|
||||
while (true) {
|
||||
try {
|
||||
await api.request("account_info", {account: address, ledger_index: "validated"})
|
||||
break
|
||||
} catch(e) {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000))
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare AccountSet transaction for the issuer (cold address)
|
||||
const cold_settings_tx = {
|
||||
"Account": cold_address,
|
||||
"TransferFee": 0,
|
||||
"TickSize": 5,
|
||||
"SetFlag": 8 // enable Default Ripple
|
||||
//"Flags": (api.txFlags.AccountSet.DisallowXRP |
|
||||
// api.txFlags.AccountSet.RequireDestTag)
|
||||
}
|
||||
|
||||
const prepared_cst = await api.prepareTransaction(cold_settings_tx, {maxLedgerVersionOffset: 10})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}) // End of api.on.('connected')
|
||||
@@ -89,6 +89,7 @@ First, configure the settings for your cold address (which will become the issue
|
||||
|
||||
- [Default Ripple][]: **This setting is required** so that users can send your token to each other. It's best to enable it _before_ setting up any trust lines or issuing any tokens.
|
||||
- [Authorized Trust Lines][]: (Optional) This setting (also called "Require Auth") limits your tokens to being held _only_ by accounts you've explicitly approved. You cannot enable this setting if you already have any trust lines or offers for _any_ token.
|
||||
**Note:** To use authorized trust lines, you must perform additional steps that are not shown in this tutorial.
|
||||
|
||||
[Default Ripple]: rippling.html
|
||||
[Authorized Trust Lines]: authorized-trust-lines.html
|
||||
@@ -106,6 +107,7 @@ Other settings you may want to, optionally, configure for your cold address (iss
|
||||
[Require Destination Tags]: require-destination-tags.html
|
||||
[Transfer Fee]: transfer-fees.html
|
||||
[Tick Size]: tick-size.html
|
||||
[Domain]: accountset.html#domain
|
||||
|
||||
**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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user